The R Project for Sta/s/cal Compu/ng Gavin Wilson Where - - PowerPoint PPT Presentation
The R Project for Sta/s/cal Compu/ng Gavin Wilson Where - - PowerPoint PPT Presentation
The R Project for Sta/s/cal Compu/ng Gavin Wilson Where to get it? R can be downloaded at: hAp://www.r-project.org R is open source
Where ¡to ¡get ¡it? ¡
- R ¡can ¡be ¡downloaded ¡at: ¡
– hAp://www.r-‑project.org ¡
- R ¡is ¡open ¡source ¡
- It ¡supports ¡Windows, ¡MacOS ¡and ¡many ¡of ¡the ¡
*nix ¡plaLorms ¡
- Very ¡ac/ve ¡development ¡community ¡with ¡
many ¡packages ¡(2,755 ¡available ¡on ¡CRAN) ¡
- Of ¡par/cular ¡interest ¡is ¡BioConductor ¡
Star/ng ¡R ¡
- Terminal-‑like ¡interface ¡
- Working ¡directories ¡
- getwd() ¡
- setwd(“/path/”) ¡
- r ¡
- File ¡-‑> ¡change ¡dir ¡
¡
Reading ¡a ¡tab-‑deliminated ¡file ¡
- m ¡= ¡read.table(file, ¡header=TRUE) ¡
– Will ¡parse ¡a ¡tab ¡delimited ¡file ¡into ¡a ¡2 ¡dimensional ¡list ¡ variable ¡named ¡“m” ¡
- For ¡example, ¡
> ¡m ¡= ¡read.table("test.txt") ¡ > ¡m ¡ ¡ ¡ ¡ ¡a ¡ ¡ ¡ ¡ ¡b ¡ 1 ¡ ¡ ¡12.75 ¡25.01 ¡ 2 ¡ ¡ ¡ ¡9.44 ¡13.56 ¡ 3 ¡ ¡ ¡11.38 ¡14.51 ¡ 4 ¡ ¡ ¡ ¡6.79 ¡22.05 ¡ 5 ¡ ¡ ¡11.35 ¡10.55 ¡ 6 ¡ ¡ ¡ ¡9.14 ¡15.68 ¡ 7 ¡ ¡ ¡10.67 ¡17.52 ¡ 8 ¡ ¡ ¡13.15 ¡10.31 ¡ Test.txt ¡ ¡ a ¡b ¡ 12.75 ¡25.01 ¡ 9.44 ¡13.56 ¡ 11.38 ¡14.51 ¡ 6.79 ¡22.05 ¡ 11.35 ¡10.55 ¡ 9.14 ¡15.68 ¡ 10.67 ¡17.52 ¡ 13.15 ¡10.31 ¡
Working ¡with ¡lists ¡
- m[r,c] ¡ ¡ ¡– ¡the ¡element ¡at ¡row ¡r, ¡
¡ ¡ ¡ ¡column ¡c ¡
- m[1,] ¡ ¡ ¡ ¡– ¡row ¡1, ¡all ¡columns ¡
- m[1:5,] ¡ ¡– ¡rows ¡1:5, ¡all ¡columns ¡
- m[,1] ¡ ¡ ¡ ¡– ¡all ¡rows ¡of ¡column ¡1 ¡
- m[,1:2] ¡ ¡– ¡all ¡rows ¡of ¡columns ¡1,2 ¡
- names(b) ¡– ¡The ¡column ¡names ¡
Plo_ng ¡Histograms ¡
> ¡hist(x[,1],col="blue",main ¡= ¡paste("N=",length(x[,1])), ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡xlim=(range(0,20)), ¡xlab=“values”) ¡ ¡ x[,1] ¡– ¡The ¡first ¡column ¡of ¡x ¡ col ¡ ¡ ¡– ¡The ¡fill ¡color ¡of ¡the ¡bars ¡ main ¡ ¡– ¡The ¡title ¡text ¡ xlim ¡ ¡– ¡The ¡range ¡of ¡the ¡x-‑axis ¡values ¡ xlab ¡ ¡– ¡The ¡x-‑axis ¡label ¡ > ¡hist(x[,2],col="green",main ¡= ¡paste("N=",length(x[,2])), ¡ ¡xlim=(range(0,30))) ¡ ** ¡Note: ¡paste("N=",length(x[,1])) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡concatenates ¡the ¡text ¡N= ¡with ¡the ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡length ¡of ¡column ¡1 ¡ ¡
ScaAer ¡Plots ¡
> ¡plot(x, ¡main="Scatterplot!", ¡pch=18, ¡col="blue") ¡ X ¡ ¡ ¡ ¡ ¡– ¡Plot ¡column ¡1 ¡vs ¡column ¡2 ¡ col ¡ ¡ ¡– ¡The ¡fill ¡color ¡of ¡the ¡points ¡ main ¡ ¡– ¡The ¡title ¡text ¡ pch ¡ ¡ ¡-‑ ¡The ¡symbol ¡for ¡the ¡points ¡