Description Usage Arguments Value See Also Examples
Apply common function over multiple objects independent of each other.
1 2 |
f |
A function to apply to the collection(s). |
l |
List of data objects. |
as.vector |
FALSE (default) for list output; TRUE for vector. |
... |
Parameters passed to |
List for telecast
, matrix for chain
.
https://github.com/robertschnitman/afp, dot
, mapply
, lapply
,
broadcast
from Julia: https://docs.julialang.org/en/v0.6.1/manual/arrays/#Broadcasting-1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | l <- list(mc = mtcars, aq = airquality, lcs = LifeCycleSavings) # Store to reference easily for the two examples below.
## 1. Extract means for each variable from 3 datasets.
mean.nr <- function(x) mean(x, na.rm = TRUE) # airquality has NA values.
output1a <- telecast(mean.nr, l) # Compare: lapply(l, function(x) mapply(mean.nr, x))
output1b <- telecast(mean.nr, l) # == rapply(l, mean.nr))
## 2. Derive distinct iterative reductions along with Reduce().
red.div <- function(y) Reduce(`/`, y)
output2 <- telecast(red.div, l)
output2 # Compare: lapply(l, function(x) mapply(red.div, x))
## 3. Apply function to subsets and output to matrix.
l <- split(mtcars, mtcars$cyl)
output <- chain(mean, l) # all(chain(mean, l) == t(sapply(l, function(z) sapply(z, mean))))
barplot(output[, 'mpg'], col = 'cyan3', ylab = 'Mean MPG', xlab = 'cyl')
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.