R has some very useful functions which implement looping in a compact form to make the life easier. The very rich and powerful family of apply functions is made of intrinsically vectorized functions. These function in R allow you to apply some function to a series of objects (eg. vectors, matrices, dataframes or files). They include:
- lapply(): Loop over a list and evaluate a function on each element
- sapply(): Same as lapply but try to simplify the result
- apply(): Apply a function over the margins of an array
- tapply(): Apply a function over subsets of a vector
- mapply(): Multivariate version of lapply
There is another function called split() which is also useful, particularly in conjunction with lapply.