mr_stack {rimu}R Documentation

Pivot a multiple-response object to long form

Description

Creates a data frame where every observation has as many rows as it has levels present, plus an id column to specify which rows go together.

Usage

mr_stack(x, ..., na.rm = FALSE)
ms_stack(x, ..., na.rm = FALSE)

Arguments

x

multiple response object

...

other multiple response objects

na.rm

drop NA values?

Value

A data frame with columns values and id, plus a column scores if x is a ms object. When more than one object is supplied, the result is an outer join of the two indindividual results, so it contains a row for every combination of an observed value from each object.

Examples

data(ethnicity)
ethnicity
mr_stack(ethnicity)

data(nzbirds)
nzbirds
ms_stack(nzbirds)

## not actually a sensible use
d <- mr_stack(ethnicity, nzbirds)
head(d)
with(d, table(ethnicity, nzbirds))
## equivalent, but more efficient
mtable(mr_na(ethnicity), mr_na(nzbirds))


[Package rimu version 0.6 Index]