recode: Recode Values

View source: R/recode.R

recodeR Documentation

Recode Values

Description

Assign new values to a vector.

Usage

recode(x, old, new, must.match = FALSE)

Arguments

x

A vector whose values will be recoded, can be character, numeric, or factor.

old

A vector of the unique values currently in the vector.

new

A vector of values which should replace the current ones.

must.match

A logical scalar indicating whether only those elements of the original vector with values in old should be returned (TRUE), or all values should be returned (FALSE, default) though some may be unchanged.

Value

A vector the same length as x (unless must.match=TRUE), with old values replaced by new values.

Examples

recode(c(1,1,1,2,3,4,1,10,3), 1:3, 1001:1003)
recode(c(1,1,1,2,3,4,1,10,3), 1:3, 1001:1003, must.match=TRUE)

JVAdams/GLFC documentation built on Jan. 5, 2023, 12:59 a.m.