recode: Recode Data

recodeR Documentation

Recode Data

Description

Converts a specified value to another value.

Usage

recode(x, from, to)

## S3 method for class 'factor'
recode(x, from, to)

## S3 method for class 'integer'
recode(x, from, to)

## S3 method for class 'character'
recode(x, from, to)

## S3 method for class 'numeric'
recode(x, from, to)

Arguments

x

a vector. Missing values (NAs) are allowed.

from

the target value to match and replace.

to

the replacement value.

Value

An object like vector with each target value replaced by the specified value.

Note

When used on numeric (type "double"), the recode function uses an approximate match within a small tolerance range to avoid mismatches due to computations.
The function sub offers greater flexibility than recode for replacing parts of text instead of the complete text.

See Also

sub, na2miss, miss2na

Examples

XT <- c(1, 2, 0, 4)
recode(XT, 0, 3)

USGS-R/smwrBase documentation built on Oct. 18, 2022, 9:55 a.m.