tapply_: Faster tapply

Description Usage Arguments Examples

View source: R/tapply_.R

Description

This function acts as a faster version of tapply for the common case of splitting an atomic vector by another atomic vector, and then applying a function.

Usage

1
tapply_(X, INDEX, FUN = NULL, ..., simplify = TRUE)

Arguments

X

An atomic vector.

INDEX

A vector coercable to factor; must be one of the common atomic types: factor, integer, numeric, or character.

FUN

The function to be applied. See more details at lapply.

...

Optional arguments to pass to FUN.

simplify

boolean; if TRUE, we unlist the output and hence return a named vector of values.

Examples

1
2
3
4
5
x <- rnorm(100)
gp <- sample( 1:10, 100, TRUE )
stopifnot( all(
  tapply(x, gp, mean) == tapply_(x, gp, mean)
) )

Kmisc documentation built on May 29, 2017, 1:43 p.m.

Related to tapply_ in Kmisc...