mutate_ntile | R Documentation |
Add a column of ntiles to a data table
mutate_ntile( DT, col, n, weights = NULL, by = NULL, keyby = NULL, new.col = NULL, character.only = FALSE, overwrite = TRUE, check.na = FALSE )
DT |
A |
col |
The column name (quoted or unquoted) for which quantiles are desired. |
n |
A positive integer, the number of groups to split |
weights |
If |
by, keyby |
Produce a grouped quantile column, as in |
new.col |
If not |
character.only |
(logical, default: |
overwrite |
(logical, default: |
check.na |
(logical, default: |
DT
with a new integer column new.col
containing the
quantiles. If DT
is not a data.table
its class may be preserved
unless keyby
is used, where it will always be a data.table
.
library(data.table) DT <- data.table(x = 1:20, y = 2:1) mutate_ntile(DT, "x", n = 10) mutate_ntile(DT, "x", n = 5) mutate_ntile(DT, "x", n = 10, by = "y") mutate_ntile(DT, "x", n = 10, keyby = "y") y <- "x" DT <- data.table(x = 1:20, y = 2:1) mutate_ntile(DT, y, n = 5) # Use DT$y mutate_ntile(DT, y, n = 5, character.only = TRUE) # Use DT$x
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.