composeVar {eatGADS} | R Documentation |
Create a composite variable.
Description
Create a composite variable out of two variables.
Usage
composeVar(GADSdat, sourceVars, primarySourceVar, newVar, checkVarName = TRUE)
Arguments
GADSdat |
|
sourceVars |
Character vector of length two containing the variable names which represent the sources of information. |
primarySourceVar |
Character vector containing a single variable name. Which of the |
newVar |
Character vector containing the name of the new composite variable. |
checkVarName |
Logical. Should |
Details
A common use case for creating a composite variable is if there are multiple sources for the same information. For example, a child and the parents are asked about the child's native language. In such cases a composite variable contains information from both variables, meaning that one source is preferred and the other source is used to substitute missing values.
Value
The modified GADSdat
.
Examples
# example data
dat <- data.frame(ID = 1:4,
nat_lang_child = c("Engl", "Ger", "missing", "missing"),
nat_lang_father = c("Engl", "Engl", "Ger", "missing"),
stringsAsFactors = TRUE)
gads <- import_DF(dat)
changeMissings(gads, "nat_lang_child", value = 3, missings = "miss")
changeMissings(gads, "nat_lang_father", value = 3, missings = "miss")
# compose variable
composeVar(gads, sourceVars = c("nat_lang_child", "nat_lang_father"),
primarySourceVar = "nat_lang_child", newVar = "nat_lang_comp")