Learn R Programming

Kmisc (version 0.5.0)

tapply_: Faster tapply

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

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

Run this code
x <- rnorm(100)
gp <- sample( 1:10, 100, TRUE )
stopifnot( all(
  tapply(x, gp, mean) == tapply_(x, gp, mean)
) )

Run the code above in your browser using DataLab