Learn R Programming

SciencesPo (version 1.02.12)

recode: Recode variable

Description

Change values of a variable in a data.frame. label.var

Usage

recode(vars, old, new, data = .data, ...)

Arguments

vars
varaible(s) to be recoded
old
the old values or arithmetic conditions.
new
the new values for all variables listed.
data
a data.frame object.
...
typically not needed parameters.

encoding

UTF-8

Examples

Run this code
df = data.frame(id=1:20, x=rnorm(20, mean=2, sd=.5),
z=sample(5, 20, rep=TRUE) )
use(df)
# recoding x  to missing value:
recode(z, old = c(1,2,3,4,5), new = c(5,4,3,2,1), data=df)

Run the code above in your browser using DataLab