recode {bbw} | R Documentation |
Recode
Description
Utility function that recodes variables based on user recode specifications. Handles both numeric or factor variables.
Usage
recode(var, recodes, afr, anr = TRUE, levels)
Arguments
var |
Variable to recode |
recodes |
Character string of recode specifications:
|
afr |
Return a factor. Default is TRUE if |
anr |
Coerce result to numeric (default is TRUE) |
levels |
Order of the levels in the returned factor; the default is to use the sort order of the level names. |
Value
Recoded variable
Examples
# Recode values from 1 to 9 to various specifications
var <- sample(x = 1:9, size = 100, replace = TRUE)
# Recode single values
recode(var = var, recodes = "9=NA")
# Recode set of values
recode(var = var, recodes = "c(1,2,5)=1")
# Recode range of values
recode(var = var, recodes = "1:3=1;4:6=2;7:9=3")
# Recode other values
recode(var = var, recodes = "c(1,2,5)=1;else=NA")
[Package bbw version 0.3.0 Index]