levelmap: Levelmap

View source: R/levelmap.R

levelmapR Documentation

Levelmap

Description

Creates character/categorical variable by mapping old values to new categories

Usage

levelmap(x, map, type = "c")

Arguments

x

A vector whose values will be mapped to new categories

map

A data.frame/data.table where the first variable is the old values and the second column is the new categories

type

Either "c" for character or "f" for factor. The parameter determines the type of vector that is returned.

Details

The function perpetuates the input label attribute to the output.

Examples

set.seed(234)
xm <- data.frame(
    A = 0:1
  , B = c("The zero category","The one category")
  , stringsAsFactors = FALSE)
x <- rbinom(50, 1, .4)
levelmap(x, xm)
levelmap(x, xm, type = "f")

thomasgstewart/tgsify documentation built on Aug. 1, 2024, 4:55 p.m.