rrrrrr…… now we know what it is but how the heck do you use it?
DESCRIPTION
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. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Rrrrrr…… now we know what it is but how the heck do you use it?](https://reader035.vdocuments.site/reader035/viewer/2022062519/568152a7550346895dc0cbc5/html5/thumbnails/1.jpg)
Rrrrrr……now we know what it is but how the heck do
you use it?
Andrew Trant
PPS Arctic - Labrador Highlands Research Group
![Page 2: Rrrrrr…… now we know what it is but how the heck do you use it?](https://reader035.vdocuments.site/reader035/viewer/2022062519/568152a7550346895dc0cbc5/html5/thumbnails/2.jpg)
I) get data
II) get data organized and formatted
III) import data
First things first
![Page 3: Rrrrrr…… now we know what it is but how the heck do you use it?](https://reader035.vdocuments.site/reader035/viewer/2022062519/568152a7550346895dc0cbc5/html5/thumbnails/3.jpg)
I) get data
II) get data organized and formatted
III) import data
First things first
![Page 4: Rrrrrr…… now we know what it is but how the heck do you use it?](https://reader035.vdocuments.site/reader035/viewer/2022062519/568152a7550346895dc0cbc5/html5/thumbnails/4.jpg)
Save as .csv file
![Page 5: Rrrrrr…… now we know what it is but how the heck do you use it?](https://reader035.vdocuments.site/reader035/viewer/2022062519/568152a7550346895dc0cbc5/html5/thumbnails/5.jpg)
I) get data
II) get data organized and formatted
III) import data
First things first
![Page 6: Rrrrrr…… now we know what it is but how the heck do you use it?](https://reader035.vdocuments.site/reader035/viewer/2022062519/568152a7550346895dc0cbc5/html5/thumbnails/6.jpg)
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”)
![Page 7: Rrrrrr…… now we know what it is but how the heck do you use it?](https://reader035.vdocuments.site/reader035/viewer/2022062519/568152a7550346895dc0cbc5/html5/thumbnails/7.jpg)
‘R’udimentarySome 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 workspace PERMANENTLY
![Page 8: Rrrrrr…… now we know what it is but how the heck do you use it?](https://reader035.vdocuments.site/reader035/viewer/2022062519/568152a7550346895dc0cbc5/html5/thumbnails/8.jpg)
‘R’ows then columnsManipulating 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,6
c = combine
![Page 9: Rrrrrr…… now we know what it is but how the heck do you use it?](https://reader035.vdocuments.site/reader035/viewer/2022062519/568152a7550346895dc0cbc5/html5/thumbnails/9.jpg)
‘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)
![Page 10: Rrrrrr…… now we know what it is but how the heck do you use it?](https://reader035.vdocuments.site/reader035/viewer/2022062519/568152a7550346895dc0cbc5/html5/thumbnails/10.jpg)
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
![Page 11: Rrrrrr…… now we know what it is but how the heck do you use it?](https://reader035.vdocuments.site/reader035/viewer/2022062519/568152a7550346895dc0cbc5/html5/thumbnails/11.jpg)
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
![Page 12: Rrrrrr…… now we know what it is but how the heck do you use it?](https://reader035.vdocuments.site/reader035/viewer/2022062519/568152a7550346895dc0cbc5/html5/thumbnails/12.jpg)
Conspi’R’ing (or plotting)
Low level: plot, hist, barplot….
High level: xyplot, dotplot, densityplot, contour, cloud
from packages, must install ‘LATTICE’
examples:
>with(fish,plot(N~transect,xlab=“transect #”, ylab=“N”))
>bwplot(voice.part ~ height, data=singer, xlab="Height (inches)")
>contour
![Page 13: Rrrrrr…… now we know what it is but how the heck do you use it?](https://reader035.vdocuments.site/reader035/viewer/2022062519/568152a7550346895dc0cbc5/html5/thumbnails/13.jpg)
Saving you’R’ plot
Plot something example:>bwplot(voice.part ~ height, data=singer, xlab="Height”)
Make it the active window (ie. click on it)
![Page 14: Rrrrrr…… now we know what it is but how the heck do you use it?](https://reader035.vdocuments.site/reader035/viewer/2022062519/568152a7550346895dc0cbc5/html5/thumbnails/14.jpg)
You’R’ own function
>testplot<-function(){}
>fix(testplot)>function(){with(fish,plot(N~transect))}
to execute the function:>testplot()
to review your function:>testplot
![Page 15: Rrrrrr…… now we know what it is but how the heck do you use it?](https://reader035.vdocuments.site/reader035/viewer/2022062519/568152a7550346895dc0cbc5/html5/thumbnails/15.jpg)
‘R’ecap
-Find, organize, import data-Manipulate, subset-Make tables-Generate plots and save plots-Make yer very own function
WHAT ELSE IS THERE?
![Page 16: Rrrrrr…… now we know what it is but how the heck do you use it?](https://reader035.vdocuments.site/reader035/viewer/2022062519/568152a7550346895dc0cbc5/html5/thumbnails/16.jpg)
Shutting down
I) Save history fileexample: oct19.History
II) Save workspace fileexample: test.Rdata
III) Close the window and save workspace image