Cut: Cut

Description Usage Arguments Details Examples

View source: R/Cut.R

Description

This function discretizes a column of numerical values and returns the values in a new column.

Usage

1
Cut(DT, NewColumn, x, breaks, include.lowest = T, ...)

Arguments

DT

The data.table for cut() to be used in.

NewColumn

The name for the new column.

x

Argument for cut(), a numeric vector which is to be converted to a factor by cutting.

breaks

Argument for cut(), either a numeric vector of two or more unique cut points or a single number (greater than or equal to 2) giving the number of intervals into which x is to be cut.

include.lowest

Argument for cut(), logical, indicating if an ‘x[i]’ equal to the lowest (or highest, for right = FALSE) ‘breaks’ value should be included.

...

Other argument for cut().

Details

It is similar to base::cut() but it also arranges the new column to be right next to the old column being discretized.

Examples

1
2
3
4
5
6
7
Discretize a continuous covariate
mtcars[, mpgCat := cut(mpg, breaks = c(10, 17, 21, 35), include.lowest = T)]

is comparable to

Cut(DT = mtcars, NewColumn = "mpgCat", x = mpg,
breaks = c(10, 17, 21, 35))

Then-Terence/LXR documentation built on March 12, 2021, 12:04 a.m.