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
2
tapply_(X, INDEX, FUN = NULL, FUN.VALUE = NULL, ..., simplify = TRUE,
  USE.NAMES = TRUE, na.last = 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.

FUN.VALUE

Optional; if specified we try to leverage vapply for computation of results.

...

Optional arguments to pass to FUN.

simplify

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

USE.NAMES

boolean; if TRUE use X as names for the result unless it had names already. Sometimes, one can achieve substantial speedups by setting this to FALSE. This option is only used when FUN.VALUE is not NULL.

na.last

Boolean, if TRUE NA values are grouped at the end. Ie, we group on the NAs as well.

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

kevinushey/Kmisc documentation built on May 20, 2019, 9:08 a.m.