[R] R reference card

Jonathan Baron baron at cattell.psych.upenn.edu
Fri Oct 27 03:00:44 CEST 2000

A student wanted a reference card, so I made the following.
Someone might want to fix it up, adapt it, make it into a
screen saver, demolish it, or whatever.  I will surely do
some of those.  My version will remain in
Here is the Latex text.  The package "hanging.sty" probably
will have to come from CTAN.
\oddsidemargin=0in \evensidemargin=0in \topmargin=-.3in
\textwidth=6.5in \textheight=9in
\parskip=0ex \parindent=0pt

\textbf{R reference card,} by Jonathan Baron


{\tt q()}: quit

{\tt <-}: assign

{\tt INSTALL}: install packages

{\tt m[,2]}: column 2 of matrix {\tt m}

{\tt m\$a}: variable {\tt a} in data frame {\tt m}

{\tt NA}: missing data

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

{\tt library(ctest)}: load (e.g.) ctest library


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

{\tt help(command)}: get help with command

{\tt library(help=ctest)}: help with library

{\tt apropos("topic")}: relevant commands

{\tt example(command)}: examples

\textbf{Input and output}

{\tt source("file")}: run the commands in {\tt file}.

{\tt read.table("file")}: read in data from a file

{\tt data.entry}: spreadsheet

{\tt scan(x)}: read a vector x

{\tt download.file}: from internet

{\tt url.show, read.table.url}: remote input

{\tt sink("file")}: output to {\tt file}, until {\tt sink()}

{\tt write(object, "file")}: writes an object to file

{\tt write.table(object,"file")}: writes a table

\textbf{Managing variables and objects}

{\tt attach(x)}: put variables in {\tt x} in search path

{\tt detach(x)}: remove from search path

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

{\tt rm(object)}: removes objects

{\tt dim(matrix)}: dimensions of a matrix

{\tt dimnames(x)}: names of dimensions

{\tt length(vector)}: length of a vector

{\tt 1:3}: is the vector {\tt 1,2,3}

{\tt rep(x,n)}: repeats the vector {\tt x n} times

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

\hangpara{2em}{1}{\tt cbind(a,b,c), rbind()}: binds columns or
rows into a matrix

{\tt merge}: merge data frames

{\tt matrix(numbers,rows,colmuns)}: creates a matrix

{\tt data.frame(vector list)}: makes a data frame

\hangpara{2em}{1}{\tt as.factor(), as.matrix(), as.vector()}: conversion

\hangpara{2em}{1}{\tt is.factor(), is.matrix(), is.vector()}: what it is

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

{\tt which(x==a)}: returns indices of {\tt x} where x==a

\textbf{Control flow}

{\tt for (i in vector)}: repeat what follows


{\tt \%*\%}: matrix multiplication


\hangpara{2em}{1}{\tt max(), min(), mean(), median(), sum()}, var(): as named

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

{\tt rank, sort} rank and sort

{\tt ave(x,y)}: averages of {\tt x} grouped by factor {\tt y}

{\tt by}: apply function to data frame by factor

\hangpara{2em}{1}{\tt apply(x,n,function)}: apply function to x
by rows (n=1) or colums (n=2)

\hangpara{2em}{1}{\tt tapply(x,list,function)}: apply function to x by list 

{\tt table}: make a table

{\tt tabulate}: tabulate a vector

\textbf{basic statistical analysis}

{\tt aov, anova, lm, glm}: linear models and anova

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

\textbf{tests in ctest library}

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

{\tt chisq.test(x)}: chi-square test on matrix {\tt x}

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

{\tt cor(a)}: show correlations

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

{\tt friedman.test}: Friedman test

\textbf{tests in mva library}

{\tt print(prcomp(x))}: principal components

{\tt kmeans()}: kmeans cluster analysis


{\tt plot(), barplot(), boxplot()}: basic plots

{\tt matplot()}: matrix plot

{\tt pairs(matrix)}: scatterplots

{\tt hist(x)}: histogram of vector {\tt x}.

{\tt coplot}: conditional plot

{\tt stropplot}: strip plot

{\tt qqplot}: quantile-quantile plot

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list