ntile {BurStMisc} | R Documentation |
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 |
result |
a character string specifying the form of the resulting value.
This must be (an abbreviation of) one of: |
reverse |
logical value: if |
checkBleed |
logical value: if |
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.
Note
A more primitive version of this function appeared in a blog post called "Miles of iles" on the Portfolio Probe website. A bit of comparison with the alternative functions in See Also may be found there.
Author(s)
Pat Burns
See Also
Examples
ntile(setNames(state.area, state.name), 10)
ntile(Loblolly$height, 5, result="factor", reverse=TRUE)
ntile(c(-10:10, rep(0, 7)), 4)