multChoiceCondense: multChoiceCondense

Description Usage Arguments Value Examples

Description

multChoiceCondense takes a set of variables and condenses them down to a single variable

Usage

1
2
multChoiceCondense(data, varList, resp = NULL, cellEntry = "number",
  multipleResponses = "first")

Arguments

data

Input dataset

varList

List of variables to condense

resp

Response used across varList indicating that the person responded to that column. If NULL, then any non-NA response will be used as the indicator.

cellEntry

Indicates what should be intered into the new variable. If 'number', then the column number will be used. If 'original', then the cell contents will be used. If 'column name', then the name of the column indicated as the response will be used.

multipleResponses

Indicates what should be done if the person has responses across multiple columns. If 'first', then the first column (in the order listed in varList) with a valid response is used. If 'last', then the first column (in the order listed in varList) with a valid response is used. If 'combine', then all valid responses are combined.

Value

A vector with the collapsed data from the input data.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# missdata<-data.frame(id = 1:1000,                                              #
#                     C1 = sample(c(1,NA),1000,replace=TRUE,prob=c(.4,.6)),     #
#                     C2 = sample(c(1,NA),1000,replace=TRUE,prob=c(.4,.6)),     #
#                     C3 = sample(c(1,NA),1000,replace=TRUE,prob=c(.4,.6)),     #
#                     C4 = sample(c(1,NA),1000,replace=TRUE,prob=c(.4,.6)),     #
#                     C5 = sample(c(1,NA),1000,replace=TRUE,prob=c(.4,.6)))     #
# View(missdata)
# varList<-c("C1","C2","C3","C4","C5")                                             #
# multChoiceCondense(data = missdata, varList = varList, cellEntry = 'number', multipleResponses = 'first')
# multChoiceCondense(data = missdata, varList = varList, cellEntry = 'number', multipleResponses = 'combine')
# respdata <- data.frame(White = sample(c("Yes", "No"), 30, replace = T, prob = c(.2, .8)),
#                        Black = sample(c("Yes", "No"), 30, replace = T, prob = c(.2, .8)),
#                        Asian = sample(c("Yes", "No"), 30, replace = T, prob = c(.2, .8)))
# respdata$Other <- ifelse(respdata$White=="No" & respdata$Black=="No" & respdata$Asian=="No", "Yes", "No")
# View(respdata)
# varList2<-c("White", "Black", "Asian", "Other")
# multChoiceCondense(data = respdata, resp = 'Yes', varList = varList2, cellEntry = 'column name', multipleResponses = 'combine')

TaylorAndrew/atClean documentation built on May 9, 2019, 4:21 p.m.