phys_filter: Physical limit filtering

View source: R/phys_filter.R

phys_filterR Documentation

Physical limit filtering

Description

Sets values outside user-specified physical limits to NA. This is commonly used to remove impossible measurements, such as relative humidity outside 0–100% or negative concentrations. The function supports per-column limits and grouping.

Usage

phys_filter(data, cols = NULL, min_val = NULL, max_val = NULL,
            group = NULL, date_col = NULL, verbose = FALSE)

Arguments

data

A data frame, matrix, or numeric vector.

cols

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

min_val

Lower limit(s). If a single value is given, it is applied to all selected columns. Otherwise, provide a vector with length equal to the number of selected columns.

max_val

Upper limit(s). Same behavior as min_val.

group

Optional grouping column (currently not used but reserved for consistency).

date_col

Optional time column (not used).

verbose

Logical; if TRUE, prints progress message.

Details

Values strictly less than min_val or strictly greater than max_val are set to NA. If min_val or max_val is NULL, that bound is not checked.

Value

A data frame or vector with out-of-range values set to NA.

Examples

phys_filter(data[1:100, c(1, 4, 17:19)], cols = 3:5, min_val = 0, max_val = 1000)

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