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 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.

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

cut, cut2, quantcut.

Examples

ntile(setNames(state.area, state.name), 10)

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

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

[Package BurStMisc version 1.1 Index]