Learn R Programming

eatGADS (version 1.1.1)

recode2NA: Recode values to NA.

Description

Recode multiple values in multiple variables in a GADSdat to NA.

Usage

recode2NA(GADSdat, recodeVars = namesGADS(GADSdat), value = "")

Value

Returns the recoded GADSdat.

Arguments

GADSdat

A GADSdat object.

recodeVars

Character vector of variable names which should be recoded.

value

Which values should be recoded to NA?

Details

If there are value labels given to the specified value, a warning is issued. Number of recodes per variable are reported.

If a data set is imported from .sav, character variables frequently contain empty strings. Especially if parts of the data are written to .xlsx, this can cause problems (e.g. as look up tables from createLookup), as most function which write to .xlsx convert empty strings to NAs. recodeString2NA can be used to recode all empty strings to NA beforehand.

Examples

Run this code
# create example GADS
dat <- data.frame(ID = 1:4, var1 = c("", "Eng", "Aus", "Aus2"),
                  var2 = c("", "French", "Ger", "Ita"),
                  stringsAsFactors = FALSE)
gads <- import_DF(dat)

# recode empty strings
gads2 <- recode2NA(gads)

# recode numeric value
gads3 <- recode2NA(gads, recodeVars = "ID", value = 1:3)


Run the code above in your browser using DataLab