ntiles {LSTbook}R Documentation

Create vector based on roughly equally sized groups

Description

Create vector based on roughly equally sized groups

Usage

ntiles(
  x,
  n = 3,
  format = c("rank", "interval", "mean", "median", "center", "left", "right"),
  digits = 3
)

Arguments

x

a numeric vector

n

(approximate) number of quantiles

format

a specification of desired output format. One of "center", "interval", "left", "right", "mean", or "median.

digits

desired number of digits for labeling of factors.

Details

This is a functional clone of mosaic::ntiles in order to avoid the dependency. It should be removed in the future, when there is no need to avoid such dependency, e.g. when {mosaic} is available on WASM.

Value

a vector. The type of vector will depend on format.

Examples

FEV |> head(20) |> mutate(group = ntiles(height, 3, format="center"))
FEV |> head(20) |> mutate(group = ntiles(height, 3, format="interval"))


[Package LSTbook version 0.5.0 Index]