Your SlideShare is downloading. ×
R Intro Workshop
R Intro Workshop
R Intro Workshop
R Intro Workshop
R Intro Workshop
R Intro Workshop
R Intro Workshop
R Intro Workshop
R Intro Workshop
R Intro Workshop
R Intro Workshop
R Intro Workshop
R Intro Workshop
R Intro Workshop
R Intro Workshop
R Intro Workshop
R Intro Workshop
R Intro Workshop
R Intro Workshop
R Intro Workshop
R Intro Workshop
R Intro Workshop
R Intro Workshop
R Intro Workshop
R Intro Workshop
R Intro Workshop
R Intro Workshop
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

R Intro Workshop

99

Published on

This is an Intro R work shop for graduate students at CSSE

This is an Intro R work shop for graduate students at CSSE

Published in: Education, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
99
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
5
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Intro Workshop Saad Chahine, PhD. May 26, 2014
  • 2. What is R? “R is a language and environment for statistical computing and graphics… similar to the S language and environment which was developed at Bell Laboratories… by John Chambers and colleagues…” “R is available as Free Software under the terms of the Free Software Foundation's GNU General Public Licenses in source code form. It compiles and runs on a wide variety of UNIX platforms and similar systems (including FreeBSD and Linux), Windows and MacOS.” http://www.r-project.org/
  • 3. Getting Started • Download and launch R • Type help() press enter
  • 4. Calculator ‘>’ is the prompt line Try: 3+5 Try: 3-5 Try: 3/5 Try: 3*5 Try: sqrt(5) Try: sum (1,3,5)
  • 5. Logic ‘>’ is the prompt line Try: 3<5 Try: 3>5 Try: 3+5==8 Try: 3+5==9
  • 6. Variables ‘<-’ assigns a value Try: x<-24 Try: x Try: x/2 Try: x Try: x<-“hello world” Try: x Try: x<-T Try: x
  • 7. Menu Bar • Saving your documents • Working directories getwd() • Saving workspace
  • 8. Help Example Try: help(ave) Try: help(mean) Try: help(mode) Try: help(median) Try: help(sd) Try: help(t.test) Try: help(anova) Try: example(ave) Try: example(mean) Try: example(mode) Try: example(median) Try: example(sd) Try: example(t.test) Try: example(anova)
  • 9. Vectors Try: c(3,5,7) Try: c(‘s’,’a’,’a’,’d’) Try: 3:7 Try: seq(3,7) Try: seq(3,7,0.25) Try: 7:3 Try: name <-c(‘s’,’a’,’a’,’d’)’ Try: name [3] Try: name [3] <- ‘d’ Try: name [4] <- ‘e’ Try: name
  • 10. Vectors Names Try: ranks <- 1:3 Try: names (ranks) <- c(“1st”,”2nd”,”3rd”, ) Try: ranks Try: ranks [first] Try: ranks [3] <-4 Try: scoRes <- c(450,578,502) Try: barplot(scoRes) Try: names(scoRes) <- c(“Bob”, “Marry”, “Jane”) Try: barplot (1:200)
  • 11. Matrices Try: matrix(0,6,7) Try: a<-1:42 Try: print (a) Try: matrix(a,6,7) Try: seats <- 1:20 Try: dim(seats) <- c(2,10) Try: print (seats)
  • 12. Access Values Try: print(seats) Try: seats[2,3] Try: seats[2,] Try: seats[1,] Try: seats[,3] Try: seats[,5:9]
  • 13. Matrix Try: MATD <-matrix(1:6,2) Try: MATE <-matrix(c(rep(1,3), rep(2,3)), 2, byrow=T) Try: MATE+MATD Try: MATD+10 Try: MATD-10 Try: MATD+10 Try: MATD Try: MATE-MATE Try: MATD-MATE Try: solve(MATD[,2:3]) Try: t(MATE) Try: MATD %*% t(MATE) Try: MATD*100 Try: MATD/MATE
  • 14. Factors Try: data = c(1,2,2,3,1,3,2,2,3,3,3,2,2,1,2) Try: fdata=factor(data) Try: fdata Try: mean(data)
  • 15. Import Data CSV 1. Find the file path 2. mydata <-read.table(”filepath”, header=T, sep=“,”) 3. mydata <-read.table(”filepath”, header=T, sep=“t”) 4. For fixed width use read.fwf
  • 16. Import Data SPSS 1. Install.packages(“me misc”) 2. library(“memisc”) 3. mydata <- as.data.set(spss.syst em.file('/CSSE R Workshop/GEDU6100 dataset.sav')) 4. mydata
  • 17. data.frame str str(mydata)
  • 18. data.frame summary summary(mydata)
  • 19. data.frame fix fix(mydata)
  • 20. Ways of calling your data - Mean (mydata$MATH) - With(mydata, mean(MATH)) - t.test(MATH~GENDER, data=mydata)
  • 21. data.frame attach attach(mydata) mean(MATH) t.test(MATH~GENDER)
  • 22. Export write.table(mydata, “filepath/mydata.txt”) Note: for export to exl, SAS, SPSS you may need to use foreign package.
  • 23. On your own Try: data() - Find a data set and str, summary & one statistical application
  • 24. Useful Packages foreign Hmisc prettyR psych ggplot2 summary(mydata describe(mydata) freq(mydata) rcorr(cbind (v1,v2,v3,v4) cor.test (v1,v2, use=“pairwise”)
  • 25. Try this last one… Try: contour(volcano) Try: persp(volcano, expand=0.2)
  • 26. Online resources http://tryr.codeschool.com http://www.ats.ucla.edu/stat/r/faq/inputdata_R.htm http://www.r-project.org/ https://www.stat.auckland.ac.nz/~paul/RGraphics/rgraphics.html
  • 27. Good Luck! saad.chahine@msvu.ca

×