Search notes:

R function: sapply

Apply a function on the elements in vector or a list.
y <- sapply(vec, fun)

Simple example

f <- function(x) { x^2 }

v <- c(4, 2, 5, 8, 7)
sapply (v, f)
#
# [1] 16  4 25 64 49
Github repository about-r, path: /functions/apply/s/basic.R

Create a vector

If the function returns mulitple elements, sapply returns a matrix.
vec <- c('abc', 'd', 'ef');

mat <- sapply(
         vec,
         function(elem) {
            c(nchar(elem), toupper(elem))
         });

class(mat);
#
#  matrix

mat;
#
#       abc   d   ef  
#  [1,] "3"   "1" "2"
#  [2,] "ABC" "D" "EF"
Github repository about-r, path: /functions/apply/s/create-matrix.R

See also

Other apply functions
Index to (some) R functions
sapply seems to roughly correspond to the Perl function map.
Common first class function: map

Index