| remove_empty_columns | R Documentation |
Removes columns that contain only NA values from a data.table.
Columns listed in excl_cols are retained even if they are empty.
remove_empty_columns(df, excl_cols = NULL, ...)
df |
A |
excl_cols |
Optional character vector of column names that must be preserved, even if all values in those columns are missing. |
... |
Additional arguments passed to methods. |
A data.table containing all original non-empty columns, plus any
columns listed in excl_cols, regardless of whether they are empty.
Columns that contain only NA values and are not explicitly preserved
are removed from the output.
dt <- data.table::data.table(
c = c(2, 2, 2),
x = c(NA, NA, NA),
y = c(NA, NA, NA)
)
remove_empty_columns(dt, excl_cols = "y")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.