lapply()
In this page:
lapply()
lapply(x, FUN) applies a function to every element of a vector or list and always returns a list, regardless of what the function itself returns. It's the most general member of the apply family, since a list result can hold values of any type or length. Use lapply() when you don't need the result simplified to a vector.
Note: lapply() always returns a list -- use sapply() instead when you want the result automatically simplified to a vector.
Example: lapply()
numbers <- list(1, 2, 3, 4)
squared <- lapply(numbers, function(x) x^2)
print(squared)
Login to try C/C++/Java/PHP code in the editor