vectorize: Robust alternative to Vectorize function that accepts any...

Description Usage Arguments Examples

Description

Returns a function that will work an arbitrary number of vectors, lists or data frames, though output may be unpredicatable in unusual applications The results are also intended to be more intuitive than Vectorize.

Usage

1
vectorize(fun, type = 1)

Arguments

fun

a two or more argument function

type

1 forces a row-wise evaluation, even on atomic vectors

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
vectorize(`+`)(c(1,2,3))
vectorize(sum)(c(1,2,3),c(1,2,3))
# Compare these results to Vectorize, which does not vectorize sum at all.
Vectorize(sum)(c(1,2,3),c(1,2,3))
# Across data frame columns.
df<-data.frame(a=c(1,2,3),b=c(1,2,3))
vectorize(sum)(df$a,df$b)
# Once again, Vectorize gives a different result
Vectorize(sum)(df$a,df$b)
# Any combination of vectors, lists, matrices, or data frames an be used.
vectorize(`+`)(c(1,2,3),list(1,2,3),cbind(c(1,2,3)))

cvarrichio/hordr documentation built on May 14, 2019, 12:53 p.m.