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.
#> y #> 1: 1 #> 2: 2