Learn R Programming

ume (version 1.5.2)

remove_empty_columns: Remove empty columns

Description

Removes columns that contain only NA values from a data.table. Columns listed in excl_cols are retained even if they are empty.

Usage

remove_empty_columns(df, excl_cols = NULL, ...)

Value

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.

Arguments

df

A data.table from which empty columns should be removed.

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.

Examples

Run this code
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")

Run the code above in your browser using DataLab