rc_factor: Recodes a character vector into a factor

Description Usage Arguments Value Examples

View source: R/rc_factor.R

Description

Recodes values of x based on pairs of values in from and to, outputting a factor. Optionally allows the ordering of factor levels based on level_idx.

Usage

1
rc_factor(x, from, to, level_idx = NULL)

Arguments

x

vector that will be recoded and turned into a factor

from

vector containing all unique values in x

to

vector containing values that will replace those in from - should be ordered in a manner so that each value in to occurs in this vector as the corresponding value in from

level_idx

vector specifying the sequence of levels in rc_factor's output - position of each value should be indexed to corresponding value in to and from.

Value

A vector or class factor

Examples

1
2
3
4
5
x <- as.character(1:10)
from <- as.character(1:10)
to <- letters[1:10]
level_idx <- rev(1:10)
rc_char(x, from, to, level_idx)

graggsd/sgcodebook documentation built on April 24, 2020, 5:39 a.m.