mr_flatten {rimu}R Documentation

Flatten a multiple-response object into a factor

Description

Convert a multiple-response object into a factor using a supplied ordering. Each observation is assigned its first level in the ordering. That is, an observation that has priorities[1] as one of its levels is assigned that value. An observation that does not priorities[1] as one of its levels, but does have priorities[2] is assigned priorities[2].

Usage

mr_flatten(x, priorities, sort=FALSE)

Arguments

x

mr object

priorities

Character vector of levels.

sort

if TRUE, the levels of the output will be in the order of priorities, if FALSE they will be in the original order

Value

A factor

Examples

data(ethnicity)
ethnicity

## NZ 'prioritised ethnicity'
priority<-c("Maori", "Pacific", "Asian", "European/Other")
eth <- mr_na(mr_recode(ethnicity, `European/Other`="European", `European/Other` = "MELAA"), FALSE)

mr_flatten(eth, priority)
mr_flatten(eth, priority, sort=TRUE)


[Package rimu version 0.6 Index]