revalue_vector: Revalue values in a vector

View source: R/utils.R

revalue_vectorR Documentation

Revalue values in a vector

Description

Similar idea to pandas.replace method using a dictionary for the value argument. Note: only works with vectors that are of type numeric (including integer) or character.

Usage

revalue_vector(x, dict, default_value = NULL, suppress_warnings = FALSE)

Arguments

x

character. Name of column to be relabelled

dict

a named vector. names(dict) are the 'keys' i.e. the existing values in df[[colname]] to be replaced. These should be unique. An error is raised if non-unique values are found in names(dict)

default_value

default value to use for values in df[[colname]] that are not present in names(dict). By default this is NULL, meaning that values not present in names(dict) will remain unchanged.

suppress_warnings

bool. A warning is raised if the column to be relabelled contains values not present in dict. This message is silenced if suppress_warnings is TRUE. Default value is FALSE.

Value

A relabelled vector.


rmgpanw/rawutil documentation built on May 20, 2022, 1:29 a.m.