select | R Documentation |
Choose or rename variables from a data.table.
select()
keeps only the variables you mention;
rename()
keeps all variables.
select(.data, ...)
select_vars(.data, ..., rm.dup = TRUE)
select_dt(.data, ..., cols = NULL, negate = FALSE)
select_mix(.data, ..., rm.dup = TRUE)
rename(.data, ...)
.data |
A data.table |
... |
One or more unquoted expressions separated by commas.
Very flexible, same as |
rm.dup |
Should duplicated columns be removed? Defaults to |
cols |
(Optional)A numeric or character vector. |
negate |
Applicable when regular expression and "cols" is used.
If |
No copy is made. Once you select or rename a data.table,
they would be changed forever. select_vars
could select across
different data types, names and index. See examples.
select_dt
and select_mix
is the safe mode of
select
and select_vars
, they keey the original copy but
are not memory-efficient when dealing with large data sets.
A data.table
select_dt
, rename_dt
a = as.data.table(iris)
a %>% select(1:3)
a
a = as.data.table(iris)
a %>% select_vars(is.factor,"Se")
a
a = as.data.table(iris)
a %>% select("Se") %>%
rename(sl = Sepal.Length,
sw = Sepal.Width)
a
DT = data.table(a=1:2,b=3:4,c=5:6)
DT
DT %>% rename(B=b)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.