October 2015
Beginner to intermediate
246 pages
4h 55m
English
These functions are equivalent to a for-each loop with the advantage that they are much more efficient in terms of performance. Basically, the function is applied over every item in a vectorized object. Its main structure is:
function(object_to_iterate_on, function, additional_arguments(separated by commas))
vapply() and apply() have additional arguments that will be covered in detail in the expanded explanations of these functions.
The function argument can be an already defined function (with its arguments), as follows:
sample.list <- list(a=runif(100,0,1), b=runif(500,0,100), c=runif(35,0,200)) sapply(sample.list, quantile, probs=0.75) ## a.75% b.75% c.75% ## 0.7145661 77.4817679 158.9351519
Read now
Unlock full access