R commander Introduction INFO 271b 9/26/2013 -------- Select a working directory for all of your R projects: File (menu) --> Change working directory... Select a location to/from which you can load all datasets. This will allow you to switch between and merge datsets from different sources easily. -------- Ways to load a dataset using the GUI: 1. Load data from package. Example: Data (menu) --> Data in packages --> Read data set from an attached package... --> select Package 'car' and Data set 'UN'. Click 'OK' 2. Load data from an R Data file. Example: Data (menu) --> Load data set... --> select dataset (hopefully it is in your working directory! If not, first put it there). Useful for datasets in R Data format that you download from external sources. 3. Load data from a txt, tab delimited or csv file. Example: Data (menu) --> Import data from text file, clipboard, or URL... --> choose a descriptive name, set field separator as Commas if csv , etc ------- Some commented R commander script from class 9/26/2013: NOTES: 1. To execute a line, make sure your cursor is on that line or it is highlighted (can highlight blocks of code). Then, click the submit button. 2. Command/ctrl + v does not work for pasting into the Rcmdr console. Go to Edit --> Paste to paste from clipboard. 3. The '#' symbol is used for comments in R, and lines starting with this will not execute: # load UN data set from car package with load method 1, or type: data(UN, package="car") UN$Country = rownames(UN) rownames(UN) = NULL # load internet users R data file from course website # by downloading into working dir w/ method 2, here # makes new dataset called "Countries" by merging UN # and InternetUsers datasets Countries = merge(UN, InternetUsers, by = "Country", all = TRUE) # load Fertility csv format dataset from course website # download into working dir w/ method 3 and load here # merge Fertility with existing Countries dataset; overwrite Countries = merge(Countries, Fertility, by ="Country", all=TRUE) summary(Countries) #summary statistics by column in dataset numSummary(Countries[,"internet_users_2011"], statistics=c("mean", "sd", "IQR", "quantiles", "skewness", "kurtosis"), quantiles=c(0,.25,.5,.75,1), type="2") numSummary(Countries$internet_users_2011) .Table <- table(Countries$region) .Table # counts for region round(100*.Table/sum(.Table), 2) # percentages for region remove(.Table) # creates histogram-- can be done through Graphs menu in GUI Hist(Countries$internet_users_2011, scale="frequency", breaks="Sturges", col="darkgray") Hist(Countries$internet_users_2011, scale="percent", breaks=30, col="darkgray") library(aplpack, pos=4) # creates stem and leaf plot -- can be done through Graphs menu in GUI stem.leaf(Countries$internet_users_2011, unit=1, na.rm=TRUE) stem.leaf(Countries$internet_users_2011, unit=1, m=1, na.rm=TRUE) showData(UN)