lkp_to_factor: Relabel factors using a named vector

Description Usage Arguments Value Examples

View source: R/factor_tools.R

Description

Relabel factors using a named vector

Usage

1
lkp_to_factor(x, lkp_vals, ..., check_names = TRUE)

Arguments

x

a character or factor vector to modify

lkp_vals

either a named vector where the names are the values in x and the values are the new levels or a character vector defining the order of the values of x.

...

additional parameters passed to factor()

check_names

check that all the names exist

Value

a factor

Examples

1
2
3
4
5
6
7
x <- c("apple", "bear", "banana", "dear")
# new value is "fruit"
levels <- c("apple" = "fruit", "banana" = "fruit")
lkp_to_factor(x, levels)

# just reorder factors
lkp_to_factor(x, c("dear", "banana", "apple", "bear"))

West-End-Statistics/r-library-vakdr documentation built on Dec. 18, 2021, 7:16 p.m.