% LaTeX source for R Reference Card

\documentclass{article}

\setlength{\textheight}{134mm}
\setlength{\textwidth}{180mm}
\setlength{\topmargin}{-18mm}
\setlength{\headheight}{0mm}
\setlength{\headsep}{0mm}
\setlength{\oddsidemargin}{-10mm}

\begin{document}

\pagestyle{empty}

\setlength{\columnsep}{24mm}
\twocolumn

\normalsize{

\parskip1.0\smallskipamount

\parindent0mm

\smallskip

\textbf{basic statistical analysis}

\hangindent1.0em
\texttt{aov()}, \texttt{anova()}, \texttt{lm()}, 
\texttt{glm()}: linear and non-\newline\mbox{linear} models, anova 

\texttt{t.test()}: t test 

\texttt{prop.test()}, \texttt{binom.test()}: sign test 

\texttt{chisq.test(x1)}: chi-square test on matrix \texttt{x1}

\texttt{fisher.test()}: Fisher exact test 

\texttt{cor(a)}: show correlations 

\texttt{cor.test(a,b)}: test correlation 

\texttt{friedman.test()}: Friedman test 

\smallskip

\textbf{some statistics in mva package}

\texttt{prcomp()}: principal components 

\texttt{kmeans()}: kmeans cluster analysis 

\texttt{factanal()}: factor analysis 

\texttt{cancor()}: canonical correlation 

\smallskip

\textbf{Graphics}

\hangindent1.0em
\texttt{plot()}, \texttt{barplot()}, \texttt{boxplot()}, \texttt{stem()}, 
\texttt{hist()}: \newline\mbox{basic} plots 

\texttt{matplot()}: matrix plot 

\texttt{pairs(matrix)}: scatterplots 

\texttt{coplot()}: conditional plot 

\texttt{stripchart()}: strip chart 

\texttt{qqplot()}: quantile-quantile plot 

\texttt{qqnorm()}, \texttt{qqline()}: fit normal distribution 

\newpage

\underline{\textbf{\textsf{R} reference card}}, by Jonathan Baron 

Parentheses are for functions, brackets are for indicating the position
of items in a vector or matrix. (Here, items with numbers like
\texttt{x1} are user-supplied variables.) 

\smallskip

\textbf{Miscellaneous }

\texttt{q()}: quit 

\texttt{<-}: assign 

\texttt{INSTALL} \texttt{package1}: install \texttt{package1}

\texttt{m1[,2]}: column 2 of matrix \texttt{m1}

\texttt{m1[,2:5]} or \texttt{m1[,c(2,3,4,5)]}: columns 2--5 

\texttt{m1\$a1}: variable \texttt{a1} in data frame \texttt{m1}

\texttt{NA}: missing data 

\texttt{is.na}: true if data missing 

\texttt{library(mva)}: load (e.g.) the \texttt{mva} package 

\smallskip

\textbf{Help}

\hangindent1.0em
\texttt{help(command1)}: get help with \texttt{command1} (NOTE: 
USE THIS FOR MORE DETAIL THAN THIS CARD CAN PROVIDE.) 

\texttt{help.start()}: start browser help 

\texttt{help(package=mva)}: help with (e.g.) package \texttt{mva}

\texttt{apropos("topic1")}: commands relevant to \texttt{topic1}

\texttt{example(command1)}: examples of \texttt{command1}

\smallskip

\textbf{Input and output}

\texttt{source("file1")}: run the commands in \texttt{file1}.

\texttt{read.table("file1")}: read in data from \texttt{file1}

\texttt{data.entry()}: spreadsheet 

\texttt{scan(x1)}: read a vector \texttt{x1}

\texttt{download.file(url1)}: from internet 

\hangindent1.0em
\texttt{url.show(url1)}, \texttt{read.table.url(url1)}: remote 
\newline\mbox{input} 

\texttt{sink("file1")}: output to \texttt{file1}, until \texttt{sink()}

\texttt{write(object,"file1")}: writes an object to \texttt{file1}

\texttt{write.table(dataframe1,"file1")}: writes a table 

\smallskip

\textbf{Managing variables and objects}

\texttt{attach(x1)}: put variables in \texttt{x1} in search path 

\texttt{detach(x1)}: remove from search path 

\texttt{ls()}: lists all the active objects. 

\texttt{rm(object1)}: removes \texttt{object1}

\texttt{dim(matrix1)}: dimensions of \texttt{matrix1}

\texttt{dimnames(x1)}: names of dimensions of \texttt{x1}

\texttt{length(vector1)}: length of \texttt{vector1}

\texttt{1:3}: the vector \texttt{1,2,3} 

\texttt{c(1,2,3)}: creates the same vector 

\texttt{rep(x1,n1)}: repeats the vector \texttt{x1} \texttt{n1} times 

\hangindent1.0em
\texttt{cbind(a1,b1,c1)}, \texttt{rbind(a1,b1,c1)}: binds 
columns or rows into a matrix 

\texttt{merge(df1,df2)}: merge data frames 

\hangindent1.0em
\texttt{matrix(vector1,r1,c1)}: make vectors into a 
matrix with \texttt{r1} rows and \texttt{c1} columns 

\smallskip

\vbox{
\hangindent1.0em
\texttt{data.frame(v1,v2)}: make a data frame from 
vectors \texttt{v1} and \texttt{v2}
}

\hangindent1.0em
\texttt{as.factor()}, \texttt{as.matrix()}, \texttt{as.vector()}: 
\mbox{conversion}

\hangindent1.0em
\texttt{is.factor()}, \texttt{is.matrix()}, \texttt{is.vector()}: what it 
is 

\texttt{t()}: switch rows and columns 

\texttt{which(x1==a1)}: returns indices of \texttt{x1} where 
\texttt{x1==a1} 

\smallskip

\textbf{Control flow}

for (\texttt{i1} in \texttt{vector1}): repeat what follows 

\texttt{if (conditions) \dots else \dots}: conditional 

\smallskip

\textbf{Arithmetic}

\%*\% matrix multiplication 

\hangindent1.0em
\%/\%, \^{}, sqrt(): integer division, power, 
\mbox{modulus}, square root 

\smallskip

\textbf{Statistics}

\hangindent1.0em
\texttt{max()}, \texttt{min()}, \texttt{mean()}, \texttt{median()}, 
\texttt{sum()}, \texttt{var()}: as named 

\texttt{summary(data.frame)}: prints statistics 

\texttt{rank()}, \texttt{sort()} rank and sort 

\texttt{ave(x1,y1)}: averages of \texttt{x1} grouped by \texttt{factor1} 

\texttt{by()}: apply function to data frame by factor 

\hangindent1.0em
\texttt{apply(x1,n1,function1)}: apply \texttt{function1} (e.g. 
\newline\texttt{mean}) to \texttt{x} by \texttt{rows(n1=1}) or 
\texttt{columns(n2=2)} 

\hangindent1.0em
\texttt{tapply(x1,list1,function1)}: apply function to 
\texttt{x1} by \texttt{list1}

\texttt{table()}: make a table 

\enlargethispage{\baselineskip}

\texttt{tabulate()}: tabulate a vector 

\smallskip

\newpage

}

\end{document}

%