The R book: Essentials of the R Language Flashcards
logs with base 10
log10()
Enter the numbers from the keyboard one at a time
scan()
Named Elements within vectors
names(counts) <- 0:8
pmax?
vector, of length equal to the longest of x, y, z, containing the maximum of x, y or z for the ith position in each
if names(data) is “Growth.rate” “Water” “Detergent” “Dephnia”, how to find the mean growth rate for each detergent
tapply(Growth.rate, Detergent, mean)
Calculate the median growth rate for water type and daphnia clone
tapply(Growth.rate, list(Water, Daphnia), median)
with function
evaluates an R expression in an environment constructed from data.
To see the names of the dataframes in the build-in package called datasets
data()
See all available data sets (including those in the installed packages)
data(package = .packages(all.available = TRUE))
subscripts on lists
double square
reverse sort on vector x
rev(sort(x))
Subscripts for values bigger than 5
which(y>5)
Every 25th value in a 100-long vector of normal random number with mean value 100 and standard deviation 10
xv <- rnorm(1000, 100, 10)
xv[seq(25, length(xv),25)]
Find logical combinations of &
outer(x, x, “&”)
repeat function
rep(1:4, each = 2, times = 3)