recode: Recode to output

Description Usage Arguments Examples

Description

Recode a vector of codes into a vector of output. If codes not mentioned, go into "Other"

Usage

1
recode(data, code_list, output_list, other = TRUE)

Arguments

data

Vector to recode

code_list

Code list

output_list

Output list (1 on 1 according to code list)

other

True: codes not mentioned go into "Other" False: codes not mentioned kept as original codes

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## The function is currently defined as
function (data, code_list, output_list, other = TRUE)
{
    data = as.character(data)
    for (i in 1:length(code_list)) {
        data = translate(data, code_list[i], output_list[i])
    }
    if (other)
        data[!data %in% output_list] = "Other"
    data
  }

longqiuyu/LongDataClean documentation built on May 28, 2019, 7:37 a.m.