levelmap: Levelmap

Description Usage Arguments Details Examples

View source: R/levelmap.R

Description

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

Usage

1
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

1
2
3
4
5
6
7
8
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 June 18, 2020, 11:10 a.m.