Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

cutWithMinN

Cut numeric vector into non-empty intervals


Description

Discretizes a numeric vector. Divides the range of x into intervals, so that each interval contains a minimum number of values, and codes the values in x according to which interval they fall into.

Usage

cutWithMinN(x, intervals=2, min.n=1)

Arguments

x

numeric vector.

intervals

number of intervals required.

min.n

minimum number of values in any interval. Must be less than or equal to length(x)/intervals.

Details

This function strikes a compromise between the base functions cut, which by default cuts a vector into equal length intervals, and quantile, which is suited to finding equally populated intervals. It finds a partition of the x values that is as close as possible to equal length intervals while keeping at least min.n values in each interval.

Tied values of x are broken by random jittering, so the partition may vary slightly from run to run if there are many tied values.

Value

A list with components:

group

integer vector of same length as x indicating which interval each value belongs to.

breaks

numeric vector of length intervals+1 giving the left and right limits of each interval.

Author(s)

Gordon Smyth

See Also

Examples

x <- c(1,2,3,4,5,6,7,100)
cutWithMinN(x,intervals=3,min.n=1)

edgeR

Empirical Analysis of Digital Gene Expression Data in R

v3.32.1
GPL (>=2)
Authors
Yunshun Chen, Aaron TL Lun, Davis J McCarthy, Matthew E Ritchie, Belinda Phipson, Yifang Hu, Xiaobei Zhou, Mark D Robinson, Gordon K Smyth
Initial release
2021-01-14

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.