Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

remove_constant

Remove constant columns from a data.frame or matrix.


Description

Remove constant columns from a data.frame or matrix.

Usage

remove_constant(dat, na.rm = FALSE, quiet = TRUE)

Arguments

dat

the input data.frame or matrix.

na.rm

should NA values be removed when considering whether a column is constant? The default value of FALSE will result in a column not being removed if it's a mix of a single value and NA.

quiet

Should messages be suppressed (TRUE) or printed (FALSE) indicating the summary of empty columns or rows removed?

See Also

remove_empty() for removing empty columns or rows.

Other remove functions: remove_empty()

Examples

remove_constant(data.frame(A=1, B=1:3))

# To find the columns that are constant
data.frame(A=1, B=1:3) %>%
  dplyr::select_at(setdiff(names(.), names(remove_constant(.)))) %>%
  unique()

janitor

Simple Tools for Examining and Cleaning Dirty Data

v2.1.0
MIT + file LICENSE
Authors
Sam Firke [aut, cre], Bill Denney [ctb], Chris Haid [ctb], Ryan Knight [ctb], Malte Grosser [ctb], Jonathan Zadra [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.