1 / 16

Rrrrrr…… now we know what it is but how the heck do you use it?

Rrrrrr…… now we know what it is but how the heck do you use it?. Andrew Trant PPS Arctic - Labrador Highlands Research Group. First things first. I) get data II) get data organized and formatted III) import data. First things first.

amy
Download Presentation

Rrrrrr…… now we know what it is but how the heck do you use it?

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. Rrrrrr……now we know what it is but how the heck do you use it? Andrew Trant PPS Arctic - Labrador Highlands Research Group

  2. First things first I) get dataII) get data organized and formattedIII) import data

  3. First things first I) get dataII) get data organized and formattedIII) import data

  4. Save as .csv file

  5. First things first I) get data II) get data organized and formattedIII) import data

  6. Importing data into R -open R and save workspace as test.Rdata#make sure you save workspace image-go into data folder and open ‘test.Rdata’ >read.csv(“ReefFishAbundance.csv”)REMEMBER: nothing is saved into the workspace environment unless you assign it a name >fish<-read.csv(“ReefFishAbundance.csv”)

  7. ‘R’udimentary Some things to try:>ls() ………………………………Lists objects>names(fish) ………….……….Lists variables>junk<-fish ……..….………..…Rename>summary(fish) ………….…… Descriptive stats>ls()>rm(junk) ……………………... Removes from ls()>rm(list=ls()) …………………. Clears workspacePERMANENTLY

  8. ‘R’ows then columns Manipulating data.frame:>fish[1,2] …………...row 1, column 2>fish[1:3,5] …………rows 1,2,3 column 5>fish[1,c(3,5:6)] …….row 1 columns 3,5,6>fish[1,-c(5:6)] …….. row 1 and NOT columns 5,6c = combine

  9. ‘R’ussian dolls Subsetting data:>subset(fish,year==1) ……….…….. equal to 1>subset(fish,year!=1) ……………… NOT equal 1>subset(subset(fish,year==2),N>170)

  10. Tables From dataset airquality (preloaded):>airquality #confusing>with(airquality,table(Temp,Month)) #better>with(airquality, table(cut(Temp, quantile(Temp)), Month)) #best#’quantile’ breaks Temp range into 4 equal parts

  11. Mo’R’e Tables >airtable<-with(airquality,table(cut(Temp,quantile(Temp)),Month))>margin.table(airtable)>margin.table(airtable,1) #sum by rows>margin.table(airtable,2) #sum by columns>prop.table(airtable)>prop.table(airtable,1) #prop by row>prop.table(airtable,2) #prop by column>summary(airtable) #Chi-squared test

  12. Conspi’R’ing (or plotting) Low level:plot, hist, barplot….High level:xyplot, dotplot, densityplot, contour, cloudfrom packages, must install ‘LATTICE’examples:>with(fish,plot(N~transect,xlab=“transect #”, ylab=“N”))>bwplot(voice.part ~ height, data=singer, xlab="Height (inches)")>contour

  13. Saving you’R’ plot Plot something example:>bwplot(voice.part ~ height, data=singer, xlab="Height”)Make it the active window (ie. click on it)

  14. You’R’ own function >testplot<-function(){}>fix(testplot)>function(){with(fish,plot(N~transect))}to execute the function:>testplot()to review your function:>testplot

  15. ‘R’ecap -Find, organize, import data-Manipulate, subset-Make tables-Generate plots and save plots-Make yer very own function WHAT ELSE IS THERE?

  16. Shutting down I) Save history file example: oct19.History II) Save workspace file example: test.Rdata III) Close the window and save workspace image

More Related