Upcoming SlideShare
×

# Presentation R basic teaching module

1,079 views

Published on

Presentation on basic R commands that are useful for biologists. With some biological examples.

Published in: Technology
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
1,079
On SlideShare
0
From Embeds
0
Number of Embeds
33
Actions
Shares
0
27
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Presentation R basic teaching module

1. 1. Introduction to R Basic Teaching module 13-10-2010Sander Timmer & Myrto Kostadima
2. 2. OverviewWhat is RQuick overview datatypes, input/output andplotsSome biological examplesI’m not a particular good teacher, so pleaseask when you’re lost!
3. 3. What is this R thing?R is a powerful, general purpose languageand software environment for statisticalcomputing and graphicsRuns on Linux, OS X and for the unlucky fewalso on WindowsR is open source and free!
4. 4. Start your R interface
5. 5. Variablesx <- 2x <- x^2x[1] 4
6. 6. VectorsMany ways of generating a vector with a range of numbers: x <- 1:10 assign(“x”, 1:10) x <- c(1,2,3,4,5,6,7,8,9,10) x <- seq(1,10, by=1) x <- seq(length = 10, from=1,by=1)x[1] 1 2 3 4 5 6 7 8 9 10
7. 7. VectorsCommon way to store multiple valuesx <- c(1,2,4,5,10,12,15)length(x)mean(x)summary(x)
8. 8. VectorsVectors are indexedx[5] + x[10][1] 15x[-c(5,10)][1] 1 2 3 4 6 7 8 9
9. 9. MatricesCommon form of storing 2 dimensional data Think about having a Excel sheetm = matrix(1:10,2,5) [,1] [,2] [,3] [,4] [,5][1,] 1 3 5 7 9[2,] 2 4 6 8 10summary(m)
10. 10. FactorsFactors are vectors with a discrete number oflevels:x <- factor(c(“Cancer”, “Cancer”, “Normal”,“Normal”))levels(x)[1] “Cancer” “Normal”table(x)Cancer Normal 2 2
11. 11. ListsA list can contain “anything”Useful for storing several vectorslist(gene=”gene 1”, expression=c(5,2,3))\$gene[1] “gene 1”\$expression[1] 5, 2, 4
12. 12. If-else statementsEssential for any programming languageif state then do x else do yif(p < 0.01){ print(“Signiﬁcant gene”)}else{ print(“Insigniﬁcant gene”)}
13. 13. RepetitionYou want to apply 1 function to everyelement of a listfor(element in list){ ....do something.... }For loops are easy though tend to be slowApply is the fast way of getting things donein R:apply(List,1,mean)
14. 14. Data inputR has countless ways of importing data: CSV Excel Flat text ﬁle
16. 16. Data inputAlso for more speciﬁc data sources:ExcelDatabase connections Mysql -> Ensembl e.g.Affy Affymetrix chips dataHapMap.........
17. 17. Data outputMost simple, the CSV ﬁle: write.csv(x, ﬁle=”myx.csv”)Save Rdata ﬁle: save(x, ﬁle=”myx.Rdata”)Save whole R session: save(ﬁle=”mysession.Rdata”)
18. 18. GraphicsQuick way to study your data is plotting itThe function “plot” in R can plot almostanything out of the box (even if this doesn’tmake sense!)
19. 19. plot(1:5,5:1)
20. 20. plot(1:5,5:1, col=”red”, type=”l”)
21. 21. plot(1:5,5:1, col=”red”, type=”l”, main="Title of this plot", xlab="x axis", ylab="y axis")
22. 22. Basic graphicsWith R you can plot almost any object Multidimensional variables like matrixes can be plotted with matplot()Other often used plot functions are: boxplot(), hist(), levelplot(), heatmap()