Skip to contents

Replace values satisfying a predicate

Usage

replace_if(x, f, values)

Arguments

x

A vector.

f

A function, called with x. The return value is used to select elements in x to replace with values.

values

Values assigned to elements of x satisfying f.

Value

The vector x with elements given by f(x) replaced with values.

See also

replace() which this thinly wraps.

Examples

replace_if(c(1, NA, 3), is.na, 42)
#> [1]  1 42  3