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

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758197384, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/R/functions/sapply(86): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78