Learn R Programming

tidyplus (version 0.2.0)

drop_uninformative_columns: Drop uninformative columns from a data frame

Description

This is a convenient way to drop columns which all have one value (missing or not) or if na_distinct = FALSE also drop columns which all have one value and/or missing values.

Usage

drop_uninformative_columns(data, na_distinct = TRUE)

Value

The original data frame with only informative columns.

Arguments

data

A data frame.

na_distinct

A flag specifying whether to treat missing values as distinct from other values.

Examples

Run this code
data <- tibble::tibble(
  a = c(1, 1, 1), x = c(NA, NA, NA), b = c(1, 1, NA),
  z = c(1, 2, 2), e = c(1, 2, NA)
)

drop_uninformative_columns(data)
drop_uninformative_columns(data, na_distinct = FALSE)

Run the code above in your browser using DataLab