R: Brief Reference Page

command function notes/examples
q( ) quit R
<- assignment x <- 17
= assignment x = 17
help( ) ask for help help(q) or ?q: help on the quit function
help.start( ) help browser
data( ) R internal datasets data(co2): atmospheric co2 dataset
Managing Data
ls( ) list objects in workspace ls(pat="^O"): list objects beginning with "O"
ls(pat="O") : list object names including an "O"
rm( ) remove objects from workspace rm("X")
attach(DF) add the data frame DF to search list
detach(DF) remove data frame DF from search list
dim(DF) dimensions of matrix or dataframe DF
names(DF) column names of dataframe DF
dimnames(DF) row and column names of DF
DF[1, ] first row of DF
DF[ ,2] second column of DF
DF[ ,"X"] column of DF named "X"
length(x) length of the vector x
sort( ) sort a dataset default is ascending order
factor( ) convert data to factor factor(x,levels=...,labels=...)
merge( ) join two data frames see help file for details and examples
Basic Statistics
mean( ) sample mean see also: weighted.mean( )
median( ) sample median
sd( ) sample standard deviation
var( ) sample variance
max( ) maximum
min( ) minimum
quantile( ) sample quantiles quantile(x,c(.1,.25,.5,.75,.9))
#a five-number summary of x
rank( ) sample rank
tabulate( ) count entries x =rep(1:5,c(2,2,4,3,6))
apply() apply a function to a data frame apply(X,1,sum): sum the rows of X
apply(X,2,sum): sum the columns of X
Hypothesis Tests
binom.test( ) exact test for binomial proportions
prop.test( ) large sample test for binomial proportions
power.prop.test( ) large sample binomial power computations
t.test( ) t test t.test(x,mu=0): one sample t test
t.test(x,y,var.equal=TRUE): two sample t test, equal variances
t.test(x,y,paired=TRUE): paired sample t test
power.t.test( ) t test power computations
aov( ) analysis of variance aov(y ~ A, data=DF)
power.anova.test( ) analysis of variance power computations
wilcox.test( ) Wilcoxon rank tests non-parametric analogs of the t test
fisher.test( ) Fisher's exact test
ks.test( ) Kolmogorov-Smirnov test
shapiro.test( ) Shapiro-Wilk test for normality
Statistical Models
lm( ) linear models (regression) lm(y ~ x, data=DF)
nls( ) non-linear least squares
glm( ) generalized linear model
summary( ) model summary summary(lm(y ~ x, data=DF))
plot( ) scatterplots plot(x,y) or plot(y ~ x)
identify( ) interactive identification of points plot(x,y)
abline( ) add line to scatterplot abline(a,b)
add the line with intercept a and slope b
qqplot( ) quantile-quantile plots qqplot(x,y)
qqnorm( ) normal quantile plots qqnorm(x); qqline(x)
scan( ) read a vector of data scan("myfile"): read the data stored as plain text in "myfile"
read.table( ) read plain text tabular data read.table("myfile",header=TRUE)
write.table( ) write a dataframe to a plain text file you may need to set the working directory first
data.entry( ) spreadsheet data entry data.entry(x,y): datasets x and y must already exist