R: Fast conditional sum

bySum {ffbase} | R Documentation

## Fast conditional sum

### Description

`bySum` works like a very fast version of tapply with (weighted) `FUN=sum`.

### Usage

    bySum(x, by, na.rm = FALSE, weight = NULL, ...)

### Arguments

`x` | `numeric` vector to be summed
`by` | (list of) `factor(s)` for which the sum will be calculated
`na.rm` | `logical` If `TRUE` `NA` values will be removed
`weight` | `numeric` with of same length as `x`
`...` | not used

### Value

`array` with dimensions of `by`

### Examples

    bySum(warpbreaks$breaks, warpbreaks$wool)
    bySum(warpbreaks$breaks, warpbreaks[,-1])

[Package ffbase version 0.13.1 Index]