Learn R Programming

ryouready (version 0.4)

collapse_responseset.data.frame: Collapse multiple response sets to single variable

Description

This functions allows to collapse several multiple response set varables into one variable. It can be applied either to a dataframe or within the transform function.

Usage

"collapse_responseset"(x, vars = NULL, rec = NULL, ...)
"collapse_responseset"(..., rec = NULL)
collapse_responseset(x, ...)

Arguments

x
A dataframe.
vars
The names or indexes of the dataframe columns that contain the multi response set. By default all variables from dataframe are used.
rec
A vector of the same length as the number of variables specifying the new values for each column.
...
Several vector of the same length (for default method).

Value

A vector with the with the new values.

Examples

Run this code
d <- data.frame(t1=c(1,0,NA,0,0),
                 t2=c(0,1,0,NA,0),
                 t3=c(0,0,1,0,0) )

 # collapse all variables of a dataframe
 collapse_responseset(d)

 # collapse columns 1 to 3 (which is all in this case as well)
 collapse_responseset(d, vars=1:3)
 collapse_responseset(d, vars=c("t1", "t2", "t3"))

 # use letters instead fo numbers for recoding
 collapse_responseset(d, vars=1:3, rec=letters[1:3])

 # use with several vectors
 collapse_responseset(d$t1, d$t2, d$t3)

 # use inside of transform
 transform(d, new=collapse_responseset(t1, t2, t3))

 transform(d, new=collapse_responseset(t1, t2, t3, rec=letters[1:3]))

Run the code above in your browser using DataLab