R Language *apply family of functions (functionals)

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

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.



Got any R Language Question?