
Last chance! 50% off unlimited learning
Sale ends in
Recode
is an alias for recode
that avoids name clashes
with packages, such as recode
function.recode(var, recodes, as.factor.result, as.numeric.result=TRUE, levels)
Recode(...)
TRUE
if
var
is a factor, FALSE
otherwise.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.recode
.var
.input=output
.
If an input value satisfies more than one specification,
then the first (from left to right) applies.
If no specification is satisfied, then the input value is carried
over to the result. NA
is allowed on input and output.
Several recode specifications are supported:
[object Object],[object Object],[object Object],[object Object]
If all of the output values are numeric, and if as.factor.result
is
FALSE
, then a numeric result is returned; if var
is a factor,
then by default so is the result.cut
, factor
x<-rep(1:3,3)
x
## [1] 1 2 3 1 2 3 1 2 3
recode(x, "c(1,2)='A';
else='B'")
## [1] "A" "A" "B" "A" "A" "B" "A" "A" "B"
Recode(x, "1:2='A'; 3='B'")
## [1] "A" "A" "B" "A" "A" "B" "A" "A" "B"
Run the code above in your browser using DataLab