better to use the sqrt function
library(microbenchmark)
set.seed(1)
x <- runif(100)
#sqrt(x)
#x^0.5
microbenchmark(sqrt(x), x^0.5)
# last "cld" column (provide ranking) available only if other package installed
other command: system.time()
pre-fetching: if you start reading the first element, it is very likely that you will read the adjacent one, in parallel the processor is already getting the next one => if you go by column: very efficient, you benefit from that
Rprof()
#[... code ...]
Rprof(NULL)
you can have amount of time spent in each function percentages do not add to 100%
garbage collector
gc()
Map a function to different group: tapply() does not apply to matrices, apply to 2 vectors 1) the one to which apply the function 2) the grouping variable
tapply(data$height, data$sex, FUN=MEAN)
=> mean of height stratify for the sex
for converting from width to short format: stack() function
for combining data frames merge() function
which element of a list present in a second list match() for each element of the first list, returns its index in the second list (if present multiple times, returns only the 1st if just want to know if they are present (not interested in the position): %in%
some functions are hidden, because not supposed to use them
retrieve their source with getAnywhere
getAnywhere(format.pval)
<<- => double arrow to use to force assignment to work on global variable, not on local variable
sample(1:100, 10, replace=T)
if we are really sure of the values we pass to the mean function, we can directly use .Internal(mean(x)) => this is the function called by mean.default() after having all the checks