map_to_value: Map Character Vector to New Values

map_to_valueR Documentation

Map Character Vector to New Values

Description

Map Character Vector to New Values

Usage

map_to_value(x, map_assignment, na, other)

Arguments

x

Character vector.

map_assignment

Vector of new values named with x values. NA values are viewed as "NA" strings, meaning that NA and "NA" will be treated as the same value. Map assignment should therefore be c("NA" = "{new_value}").

other

The value to map all other values not in map_assignment. Required only if map_assignment is incomplete.

Details

This function converts x to factor, recodes the factor, and then returns the recoded factor vector as character.

Value

A character vector of the same length as x.

Examples

## Not run: 
x <- c('T', 'R', 'H', 'W', 'P', 'NA', NA_character)
map_to_value(
  x = x,
  map_assignment =
  c('T' = 'red',
    'R' = 'green'),
  other = 'black'
)

map_to_value(
  x = x,
  map_assignment =
  c('T' = 'red',
    'R' = 'green',
    'NA' = 'white'),
  other = 'black'
)

## End(Not run)

meerapatelmd/suzyBakeOven documentation built on March 30, 2022, 1:44 p.m.