ave2: Apply function over level combinations of factors

Description Usage Arguments Value See Also Examples

Description

Group a vector into subsets according to level combinations of one or several factors and apply a function separately to every subset. This function differs from ave in three respects. Firstly, factors have to be supplied in an explicit list. Secondly, the function is a positional parameter. Thirdly and most importantly, there is now a way to supply any number of additional arguments to the function via ... as in the apply-family of functions.

Usage

1
ave2(x, factors, f, ...)

Arguments

x

Atomic vector

factors

List of factors of the same length as x.

f

Function

...

Further arguments to f

Value

A vector of the same length as x. Subsets of the result vector equal the result of applying f to the corresponding subsets of x.

See Also

ave

Examples

1
2
3
4
5
6
stopifnot(identical(
    ave2(c(1, 2, 3, 4), list(c(1, 1, 2, 2)),
        function(x, sep) {
            paste(x, rev(x), sep = sep)
        }, "-"),
    c("1-2", "2-1", "3-4", "4-3")))

cbaumbach/miscFun documentation built on May 13, 2019, 1:48 p.m.