Learn R Programming

ryouready (version 0.4)

recode2: Wrapper for recode from car to allow to recode multiple columns at once

Description

Wrapper for recode from car to allow to recode multiple columns at once

Usage

recode2(x, vars = NULL, ...)

Arguments

x
A dataframe.
vars
A vector of variable names or numeric indexes to select the columns to recode.
...
Arguments that are passed on to recode from car (see ?recode for more info).

recodes
Character string of recode specifications: see below.
as.factor.result
Return a factor; default is TRUE if the column is a factor, FALSE otherwise.
as.numeric.result
If TRUE (the default), and as.factor.result is FALSE, then the result will be coerced to numeric if all values in the result are numerals — i.e., represent numbers.
levels
An optional argument specifying the order of the levels in the returned factor; the default is to use the sort order of the level names.
...
More arguments passed to recode.

Value

A dataframe with recoded columns.

Examples

Run this code
a <- attitude
rec <- "0:50=1; 51:70=2; 60:100=3; else=NA"
recode2(a, recodes=rec)
recode2(a, vars=1:2, recodes=rec)
recode2(a, vars=c("rating", "complaints"), recodes=rec)

Run the code above in your browser using DataLab