dropWhen: Remove columns from data frames when all rows have specific...

View source: R/dropWhen.R

dropWhenR Documentation

Remove columns from data frames when all rows have specific values

Description

Remove columns from data frames when all rows have specific values

Usage

dropWhen(df, unique = FALSE, trash = NULL, requireAll = TRUE, except = NULL)

Arguments

df

Data frame to column filter

unique

Boolean for whether to return only unique rows after column filtering

trash

Character vector containing all the trash values, besides NA, for which a column can be removed

requireAll

Boolean as to whether you want to require all rows in a column to equal a value in 'trash' before filtering the column out (TRUE).

except

Character vector containing all column names to ignore when dropping columns (these will be retained regardless of the other parameter choices).

Value

Returns a column filtered data frame. Note, does not take into account numeric, integer or character value differences (it will treat them all the same).

Examples

df <- data.frame(this = c(NA, seq(1, 5, 1), seq(1, 5, 1)), that = rep(0, 11),
thisotherThing = rep(NA),
ohAndThis = rep(c("trashValue", "0"), 11))
cleanerdf <- dropWhen(df, unique = FALSE, trash = c("0", "trashValue"), requireAll = FALSE)

FredHutch/tgR.data documentation built on May 30, 2022, 9:30 a.m.