1 / 9

Getting Help on R

Getting Help on R. Manuals, Packages, and FAQs on R http://www.r-project.org/ (click on Manuals) help.start() (activates Manual) ?insert function name or for fuzzy matching help.search(“insert”) R archives: http://finzi.psych.upenn.edu/search.html Books on R

mweathers
Télécharger la présentation

Getting Help on R

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Getting Help on R • Manuals, Packages, and FAQs on R • http://www.r-project.org/ (click on Manuals) • help.start() (activates Manual) • ?insert function name or for fuzzy matching help.search(“insert”) • R archives: http://finzi.psych.upenn.edu/search.html • Books on R • Venables and Ripley (2002) **Classic** • Faraway (2006) • Bolker (2007) **My favourite** • R Ref Card • R help Digest: https://stat.ethz.ch/mailman/listinfo/r-help • Google it! Just type R and function of interest. • Ask other grad students, postdocs…

  2. Getting Help • help.start() • ?read.table • http://www.zoology.ubc.ca/~ally/zoo502/zoo502.html

  3. Bringing Data into R • click on R-stuff • download the Example Data set (use right click and Save Tgt Link) • create a text file – a new script or in Mac (a New Document) • comment your script files #Title: #Author: #Date originally written: #Date modified: • Using read.table() we will bring the example data into R as a start. • using setwd(dir) – this is especially good for when you set up loops later. • file.choose() – if the place your files lives is transient • assign your data a name like mydata mydata<-as.data.frame(read.table(file.choose()))

  4. You need to change the header names so that they do not have odd symbols • a variable like Total VO2 (L.hr-1) has to be converted to something convenient like Total_VO2 • make sure all header names are on the same line • no spaces • units of measurement can be stored in your script file or commented out. What about missing data? • use the argument na.strings=“?” what happens? • or if blanks use fill=T

  5. Getting data into R • read.table() has the following arguments: • file (the name of the file) • header=T (do you have a row with column names) • sep=“,” or “ “ or "\t“ • na.strings (tells you that missing data has ?) • as.is (very important) • skip (if you have written something can say skip=2, will skip first two lines of the datafile) • check.names • fill=T (blank fields added if empty cells) • blank.lines.skip=T (blank lines ignored) • comment.char=“#” • as. data.frame() vs. as.matrix

  6. Check the data are the variables what you think they are? str(mydata) head(mydata,nrows) tail(mydata,nrows) sapply(mydata, class) sapply(mydata, mode) or if you want to combine the two use rbind rbind(class=sapply(x, class), mode=sapply(x, mode))

  7. Basic data types • integer (signed) • numeric (real numbers) • logical (TRUE or FALSE) • character (alphanumeric strings) • dates • factors (how R deals with categorical variables)

  8. not including as.is Plot Date Weight Total_VO2 Group Temperature class "integer" "factor" "factor" "factor" "factor" "integer" mode "numeric" "numeric" "numeric" "numeric" "numeric" "numeric" character variables are reads as factors Plot Date Weight Total_VO2 Group Temperature class "integer" "character" "character" "character" "character" "integer" mode "numeric" "character" "character" "character" "character" "numeric" as.is=T

  9. Managing the data • LONG vs WIDE formats • stack() unstack() • reshape() • melt/recast/cast() in library (reshape) • Subsetting data • subset() • library(doBy) • Indexing [,3] vs. [3,] • y<-x[!is.na(x)] • Replacements • mydata[4, “Weight”]=22.2 (Take the 4th observation and replace with value 22.2)

More Related