change_values: Change Values

View source: R/change_values.R

change_valuesR Documentation

Change Values

Description

Replace specific values in a vector with new values.

Usage

change_values(x, ..., .default = NULL)

Arguments

x

A vector in which values will be replaced.

...

An ellipsis of pairs of values to be replaced. Each pair consists of the original value and the corresponding replacement value.

.default

The default value to be used for elements not specified in the replacement pairs. If not provided, elements not specified will remain unchanged.

Value

A modified vector with replaced values.

Examples

## Retains NAs
change_values(c(1, 2, 3, NA), 2 ~ "two", 3 ~ "three")

## Set a specific default value
change_values(c(1, 2, 3), 2 ~ "two", .default = "default")

## No error message when no value to convert is found
change_values(c(1, 2, 3), 4 ~ "four")

## Recode NAs and implicit conversion from numeric to character
change_values(c(NA, 1, NA, 2), NA ~ "This is a missing value")


jazznbass/wmisc documentation built on Oct. 29, 2024, 5:42 p.m.