collapse_responseset: Collapse multiple response sets to single variable

Description Usage Arguments Value Author(s) Examples

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

1
2
3
4
5
6
7
## S3 method for class 'data.frame'
collapse_responseset(x, vars = NULL, rec = NULL, ...)

## Default S3 method:
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.

Author(s)

Mark Heckmann

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
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]))

ryouready documentation built on May 1, 2019, 8:39 p.m.