Auto recode a variable in a GADSdat
. A look up table is created containing the respective recode pairs.
An existing look up table can be utilized via template
. This function somewhat mirrors the functionality provided
by the SPSS
function autorecode
.
Usage
autoRecode(
GADSdat,
var,
var_suffix = "",
label_suffix = "",
csv_path = NULL,
template = NULL
)
Arguments
- GADSdat
A
GADSdat
object.- var
Character string of the variable name which should be recoded.
- var_suffix
Variable suffix for the newly created
GADSdat
. If an empty character, the existing variables are overwritten.- label_suffix
Suffix added to variable label for the newly created variable in the
GADSdat
.- csv_path
Path for the
.csv
file for the look up table.- template
Existing look up table.
Details
If an existing template
is used and a look up table is saved as a .csv
file, the resulting look up
table will contain the existing recodes plus additional recode pairs required for the data.
Examples
gads <- import_DF(data.frame(v1 = letters))
# auto recode without saving look up table
gads2 <- autoRecode(gads, var = "v1", var_suffix = "_num")
# auto recode with saving look up table
f <- tempfile(fileext = ".csv")
gads2 <- autoRecode(gads, var = "v1", var_suffix = "_num", csv_path = f)