Learn R Programming

dataprep (version 0.1.8)

filter_low_var: 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)

Value

A data frame with low-variance columns removed.

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.

Examples

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

Run the code above in your browser using DataLab