This function is a wrapper around the base base::lapply function that allows for the application of a function over a list or vector. It optionally allows for the suppression of the function's return value, making it useful for operations where the user is only interested in the side effects of the function.
Arguments
- X
A list or vector. The input data over which
FUN
is to be applied.- FUN
A function to be applied to each element of
X
.- Silent
A logical value. If
TRUE
, the function suppresses the return value ofFUN
and returnsNULL
invisibly. IfFALSE
, the function returns the result of applyingFUN
overX
.- ...
Additional arguments to be passed to
FUN
.
Value
If Silent
is TRUE
, returns NULL
invisibly, otherwise returns a
list of the same length as X
, where each element is the result of
applying FUN
to the corresponding element of X
.
Examples
par(mfrow = c(1,2), oma = c(0.25, 0.25, 0.25, 0.25), mar = c(3,3,3,1))
lapply(list(x = 100:110, y = 110:120), function(V) {
plot(V, las = 1, main = "lapply")
})
#> $x
#> NULL
#>
#> $y
#> NULL
#>
# -------------------------------------------
par(mfrow = c(1,2), oma = c(0.25, 0.25, 0.25, 0.25), mar = c(3,3,3,1))
lapply_(list(x = 100:110, y = 110:120), function(V) {
plot(V, las = 1, main = "lapply_")
})