This function replaces specified values within a vector with new values.

replace_values(vec, old_values, new_values)

Arguments

vec

The original vector in which values need to be replaced.

old_values

A vector containing the old values to be replaced.

new_values

A vector containing the new values to replace the old ones.

Value

A vector with the old values replaced by the new values.

Examples

replace_values(c(1, 2, 3, 4), c(2, 4), c(20, 40))
#> [1]  1 20  3 40