createCombinedVar {exceldata} | R Documentation |
Create a combined variable from several dichotomous variables
Description
This function will create a single variable from a set of dichotomous variables, usually checkbox items from a survey. The combined variable may be if there are a small number of popular response patterns. Currently this function only works with dichotomous variables.
Usage
createCombinedVar(data, dictionary, newVarName, varsToCombine, responseVal)
Arguments
data |
is data returned by the importExcelData or readExcelData functions |
dictionary |
is the data dictionary returned by importExcelData or readDataDict functions |
newVarName |
the name of the new variable. |
varsToCombine |
a vector of the first and last variables to combine into the new variable. Note that the variables to be conbined mut be contiguous in the data. |
responseVal |
the value of the variables to be combined, usually this will be 1 for 0,1 variables or Yes for Yes No or Checked for Checked Unchecked |
Details
The instructions are contained in the Levels column of the data dictionary and should be in the format: original_varname,newCode1=oldcode1,oldCode2,...,newCode2=oldCode3,..
For Example: instructions="T_Stage,T0=T0,T1up=T1,T2,T3,T4"
will recode T1-T4 as T1up and retain T0 as is