In general you can always find the argument list of a function f by typing args(f) and get a detailed description by typing help(f).
apply(x,1,f) (or apply(x,2,f)) | apply function f to each row (or column) of matrix x |
c(1:5,7) | Returns vector with numbers 1 to 5 and 7 |
cbind(x,y,z) (r rbind(x,y,z)) | make a matrix with columns (or rows) from x,y and z |
ceiling(x) (and floor(x)) | smallest integer greater or equal to x |
cumsum(x) | at each index i have x[1]+..+x[i] |
Distributions | Leading r (like rnorm) returns a random sample |
Leading d (like dnorm) returns density | |
Leading p (like pnorm) returns a cdf | |
Leading q (like qnorm) returns quantiles | |
hist(x) | draws a histogram of data in x |
ifelse(x>5,0,1) | if x>5 return 0, otherwise return 1 |
lines(x,y) | add a line to a graph |
ls() or objects() | return a listing of the functions (like “dir”) |
matrix(0,3,5) | initialize a matrix with 3 columns and 5 rows with zeros |
x[order(y)] | sort vector x according to the order in vector y |
par() | sets up a graphic, things such as more than one graph on 1 page, margins, titles etc. |
paste(“A”,1:5,sep="") | make a vector of characters “A1”, .., “A5” |
plot(x,y) | Scatterplot of x vs. y |
print(c(x,y)) | output vector c(x,y) to screen |
quantile(x,0.8) | finds the 80th percentile of the vector x |
x = rep(1,10) | Initializes a vector x of length 10 with 1s |
sample(x,size=n,replace=F) | take a random sample from vector x |
seq(0,10,length=100) | generates a vector of length 100 with numbers equally spaced from 0 to 10 |
segments(x1,y1,x2,y2) | adds line segments from (x1,y1) to (x2,y2) to a graph |
sort(x) | obvious |
table(x) or table(x,y) | tabulate the values in x, cross-tabulate the values in x and y |