RECODE: Recode a variable.

Description Usage Arguments Value Examples

View source: R/bruceR_stats_02_scale.R

Description

Based on car::recode().

Usage

1
RECODE(var, recodes)

Arguments

var

Variable (numeric, character, or factor).

recodes

Character string: e.g., "lo:1=0; c(2,3)=1; 4=2; 5:hi=3; else=999".

Value

A vector of recoded variable.

Examples

1
2
3
4
5
d=data.table(var=c(NA, 0, 1, 2, 3, 4, 5, 6))
d

d[,":="(var.recoded=RECODE(var, "lo:1=0; c(2,3)=1; 4=2; 5:hi=3; else=999"))]
d

bruceR documentation built on June 22, 2021, 1:06 a.m.