rec: Recode number or strings

recR Documentation

Recode number or strings

Description

Recode discrete variables, including numerice and character variable.

Usage

rec_num(x, rec, keep = TRUE)

rec_char(x, rec, keep = TRUE)

Arguments

x

A numeric or character vector.

rec

String with recode pairs of old and new values. Find the usage in examples.

keep

Logical. Decide whether to keep the original values if not recoded. Defaults to TRUE.

Value

A vector.

See Also

rec

Examples


x = 1:10
x
rec_num(x, rec = "1=10; 4=2")
rec_num(x, rec = "1:3=1; 4:6=2")
rec_num(x, rec = "1:3=1; 4:6=2",keep = FALSE)

y = letters[1:5]
y
rec_char(y,rec = "a=A;b=B")
rec_char(y,rec = "a,b=A;c,d=B")
rec_char(y,rec = "a,b=A;c,d=B",keep = FALSE)


hope-data-science/tidyfst documentation built on Sept. 23, 2024, 8:05 p.m.