Skip to contents

Replaces values in a numeric vector that fall outside the specified range with NA. Values already NA in the input remain NA.

Usage

filter_na_range(x, min_value = -Inf, max_value = Inf)

Arguments

x

A numeric vector to filter

min_value

Minimum value (inclusive). Values below this become NA. Default is -Inf (no lower bound).

max_value

Maximum value (inclusive). Values above this become NA. Default is Inf (no upper bound).

Value

A numeric vector the same length as x with out-of-range values replaced by NA

Examples

filter_na_range(c(1, 5, 10, 15), min_value = 3, max_value = 12)
#> [1] NA  5 10 NA
# Returns: c(NA, 5, 10, NA)

filter_na_range(c(1, NA, 10), min_value = 5)
#> [1] NA NA 10
# Returns: c(NA, NA, 10)