View source: R/drop_constant_cols.R
drop_constant_cols | R Documentation |
Drops columns that have only one value in a data.table
.
drop_constant_cols(DT, copy = FALSE)
DT |
A |
copy |
(logical, default: |
If DT
is a data.frame
that is not a data.table
,
constant columns are still dropped, but since DT
will be copied, copy
should be set
to TRUE
to avoid a warning. If DT
is a data.frame
and all but one
of the columns are constant, a data.frame
will still be returned, as opposed to the values of the sole remaining column, which is the
default behaviour of base data.frame
.
If all columns are constant, drop_constant_cols
returns a Null data table if DT
is a data.table
,
but a data frame with 0 columns and nrow(DT)
otherwise.
library(data.table) X <- data.table(x = c(1, 1), y = c(1, 2)) drop_constant_cols(X)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.