# RIntro / RIntroBrief.Rnw

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 \documentclass{article} \title{A Very Brief Introduction to R} \author{Sean Davis} \date{June 21, 2013} \begin{document} \maketitle \section{Vectors} <<>>= x = 1 x y = rep('a',10) y z = rnorm(15) z z<0 z[z<0] @ \section{Matrices} <<>>= m = matrix(rnorm(100),ncol=5) ncol(m) nrow(m) dim(m) summary(m) # first column of m m[,1] # first row of m m[1,] # get a big matrix from R data(volcano) dim(volcano) @ \section{Factors} Remember that factors are used for storing categorical variables. They often look like character vectors, but they do not have quotes'' when R prints them. Also, they behave more like numeric vectors. <<>>= cvec = rep(c('a','b'),each=10) cvec f = factor(cvec) f levels(f) # we can change the levels of the factor levels(f) = c('d','e') f as.character(f) @ \section{Data Frames} <<>>= df = data.frame(m,f) dim(df) head(df) colnames(df) df$X1 summary(df) @ \section{Plotting} This is where your curiosity and experimentation come in handy. R has many plotting capabilities and some trial and error may be necessary to get what you want from R graphics. <>= plot(df[,1],df[,2],col=df$f,pch=2,main='A simple plot') @ \section{Package installation} <>= source('http://bioconductor.org/biocLite.R') library(BiocInstaller) biocLite(c('genefilter','qvalue')) @ \subsection{Getting Help on a Package} <>= help(package='genefilter') @ \end{document}