binvec {matter}R Documentation

Bin a vector

Description

Bin a vector based on intervals or groups.

Usage

binvec(x, u, v, method = "sum")

Arguments

x

A numeric vector.

u, v

The (inclusive) lower and upper indices of the bins, or a factor providing the groupings.

method

The method used to bin the values. This is efficiently implemented for "sum", "mean", "min" or "max". Providing a function will use a less-efficient fallback.

Value

An vector of the summarized (binned) values.

Author(s)

Kylie A. Bemis

Examples

set.seed(1)

x <- runif(20)

binvec(x, c(1,6,11,16), c(5,10,15,20), method="mean")

binvec(x, seq(from=1, to=21, by=5), method="mean")

g <- rep(c("a","b","c","d"), each=5)

binvec(x, g, method="mean")

[Package matter version 1.20.0 Index]