filter_low_var: Remove low-variance (near-constant) variables

View source: R/filter_low_var.R

filter_low_varR Documentation

Remove low-variance (near-constant) variables

Description

Removes numeric columns whose variance (or standard deviation) falls below a specified threshold.

Usage

filter_low_var(data, cols = NULL, cutoff = 0.01,
               method = "var", verbose = FALSE)

Arguments

data

A data frame.

cols

Column indices or names of numeric variables to check. If NULL, all numeric columns are used.

cutoff

Variance (or standard deviation) threshold. Columns with statistic <= cutoff are removed.

method

Statistic to use: "var" for variance, "sd" for standard deviation.

verbose

Logical; if TRUE, prints removed column names and their variance.

Details

Variance is computed with NA values removed. For method = "sd", the standard deviation is compared directly against cutoff; no internal squaring is performed.

Value

A data frame with low-variance columns removed.

Examples

data <- data.frame(
  id = 1:100,
  const = rep(5, 100),
  noise = rnorm(100, sd = 0.005)
)
filter_low_var(data, cutoff = 0.001)

dataprep documentation built on Oct. 1, 2026, 5:07 p.m.