recodev

Share:

Description

This function takes a vector original.vector, and converts all values in a vector old.values to the values in a new vector new.values.

Usage

1
recodev(original.vector, old.values, new.values, others = NULL)

Arguments

original.vector

A vector you want to recode

old.values

A vector of length M.

new.values

A vector of length M.

others

An optional value indicating what to convert all values in original.vector that are not found in old.values.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
x <- c("y", "y", "XSF", "y", "0", "X", "0", "0", "y", "n", "0", "1", "1")
recodev(original.vector = x,
         old.values = c("y", "1", "n", "0"),
         new.values = c(1, 1, 0, 0)
)


x <- c("y", "y", "XSF", "y", "0", "X", "0", "0", "y", "n", "0", "1", "1")
recodev(original.vector = x,
         old.values = c("y", "1", "n", "0"),
         new.values = c(1, 1, 0, 0),
         others = NA
)