*apply family of functions (functionals)

Download r eBook

Remarks

A function in the *apply family is an abstraction of a for loop. Compared with the for loops *apply functions have the following advantages:

  1. Require less code to write.
  2. Doesn't have an iteration counter.
  3. Doesn't use temporary variables to store intermediate results.

However for loops are more general and can give us more control allowing to achieve complex computations that are not always trivial to do using *apply functions.

The relationship between for loops and *apply functions is explained in the documentation for for loops.

Members of the *apply Family

The *apply family of functions contains several variants of the same principle that differ based primarily on the kind of output they return.

functionInputOutput
applymatrix, data.frame, or arrayvector or matrix (depending on the length of each element returned)
sapplyvector or listvector or matrix (depending on the length of each element returned)
lapplyvector or listlist
vapplyvector or `listvector or matrix (depending on the length of each element returned) of the user-designated class
mapplymultiple vectors, lists or a combinationlist

See "Examples" to see how each of these functions is used.

Related Examples

Stats

100 Contributors: 8
Tuesday, August 9, 2016
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook