telecast: Apply common function over multiple objects independent of...

Description Usage Arguments Value See Also Examples

View source: R/telecast.r

Description

Apply common function over multiple objects independent of each other.

Usage

1
2
telecast(f, l, as.vector = FALSE, ...)
chain(f, l)

Arguments

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 mapply.

Value

List for telecast, matrix for chain.

See Also

https://github.com/robertschnitman/afp, dot, mapply, lapply, broadcast from Julia: https://docs.julialang.org/en/v0.6.1/manual/arrays/#Broadcasting-1

Examples

 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')

robertschnitman/afp documentation built on Aug. 9, 2020, 9:46 a.m.