Learn R Programming

SciencesPo (version 1.3.9)

recode: Recode or Replace Values With New Values

Description

Recodes a value or a vector of values.

Usage

recode(x, from, to, warn = TRUE)

## S3 method for class 'default': recode(x, from, to, warn = TRUE)

Arguments

x
The vector whose values will be recoded.
from
a vector of the items to recode.
to
a vector of replacement values.
warn
A logical to print a message if any of the old values are not actually present in x.

encoding

UTF-8

Examples

Run this code
x <- LETTERS[1:5]
recode(x, c("B", "D"), c("Beta", "Delta"))

# On numeric vectors
x <- c(1, 4, 5, 9)
recode(x, from = c(1, 4, 5, 9), to = c(10, 40, 50, 90))

Run the code above in your browser using DataLab