map_rvec {rvec} | R Documentation |
Apply a Function and Put Results in an Rvec
Description
Apply function .f
to each element of .x
,
and then combine the results into an
rvec with the same length as .x
.
Usage
map_rvec(.x, .f, ...)
Arguments
.x |
A vector. |
.f |
A function. |
... |
Additional arguments passed to |
Details
Each call to function .f
should produce
an rvec with length 1.
Value
An rvec with the same
length as .x
.
See Also
map_rvec()
is based on the
map functions in package
purrr,
though the internal implementation is different.
Base R functions sapply()
and vapply()
do not work properly with rvecs.
[lapply() works, but to combine the
results into a single rvec, functions such
as c()
or vctrs::vec_c()
are needed.
Examples
l <- list(a = rvec(matrix(1:2, 1)),
b = rvec(matrix(1:4, 2)),
c = rvec(matrix(1:6, 3)))
l
map_rvec(l, sum)
## sapply does not work with rvecs
sapply(l, sum)
[Package rvec version 0.0.6 Index]