binvec: Bin a vector

Description Usage Arguments Value Author(s) Examples

View source: R/utils.R

Description

Bin a vector based on intervals or groups.

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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")

Example output

Loading required package: BiocParallel
Loading required package: Matrix
Loading required package: biglm
Loading required package: DBI

Attaching package:matterThe following object is masked frompackage:biglm:

    biglm

The following objects are masked frompackage:base:

    apply, scale

[1] 0.4640751 0.6389526 0.4446999 0.6729408
[1] 0.4640751 0.6389526 0.4446999 0.6729408
[1] 0.4640751 0.6389526 0.4446999 0.6729408

matter documentation built on Nov. 8, 2020, 6:15 p.m.