ntile {BurStMisc} | R Documentation |
Creates groups where the groups each have as close to the same number of members as possible.
ntile(x, ngroups, na.rm = FALSE, result = "list", reverse = FALSE, checkBleed = TRUE)
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 |
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.
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.
Pat Burns
ntile(setNames(state.area, state.name), 10) ntile(Loblolly$height, 5, result="factor", reverse=TRUE) ntile(c(-10:10, rep(0, 7)), 4)