Applying Functions to Lists
Two functions are handy for applying functions to lists:
Using the lapply() and sapply() Functions
lapply() (for list apply) works like the matrix
apply() function, calling the specified function on each component of a list (or vector coerced to a list) and returning another list. Here’s an example:
> lapply(list(1:3,25:29),median) []  2 []  27
median() to 1:3 and to 25:29, returning a list consisting of 2 and 27.
In some cases, such as the example here, the list returned by
lapply() could be simplified to a vector or matrix. This is exactly what
sapply() (for simplified [l]apply) does.
> sapply(list(1:3,25:29),median)  2 27
You saw an example of matrix output in ...