BurStMisc (version 1.1)

ntile: Membership of ntile groups

Description

Creates groups where the groups each have as close to the same number of members as possible.

Usage

ntile(x, ngroups, na.rm = FALSE, result = "list", reverse = FALSE, checkBleed = TRUE)

Arguments

x
a numeric vector.
ngroups
a positive integer giving the number of groups to create.
na.rm
logical value: if TRUE, then missing values are removed before forming the groups.
result
a character string specifying the form of the resulting value. This must be (an abbreviation of) one of: "list", "numeric", "factor"
reverse
logical value: if TRUE, then the biggest values are in group 1.
checkBleed
logical value: if TRUE, then a warning is issued if the same value appears in more than one group.

Value

the form of the value depends on the result argument.The "list" result has the values of the input x grouped into ngroups components.The "numeric" result is a vector of integers from 1 to ngroups indicating which group the corresponding element of x is in.The "factor" result is an ordered factor version of the "numeric" result.

See Also

cut, cut2, quantcut.

Examples

Run this code
ntile(setNames(state.area, state.name), 10)

ntile(Loblolly$height, 5, result="factor", reverse=TRUE)

ntile(c(-10:10, rep(0, 7)), 4)

Run the code above in your browser using DataLab