| drop_constant_cols {hutils} | R Documentation |
Drop constant columns
Description
Drops columns that have only one value in a data.table.
Usage
drop_constant_cols(DT, copy = FALSE)
Arguments
DT |
A |
copy |
(logical, default: |
Details
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.
Examples
library(data.table)
X <- data.table(x = c(1, 1), y = c(1, 2))
drop_constant_cols(X)