| map_rvec | R Documentation |
Apply function .f to each element of .x,
and then combine the results into an
rvec with the same length as .x.
map_rvec(.x, .f, ...)
.x |
A vector. |
.f |
A function. |
... |
Additional arguments passed to |
Each call to function .f should produce
an rvec with length 1.
An rvec with the same
length as .x.
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 vec_c() are needed.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.