Learn R Programming

rimu (version 0.6)

mr_flatten: 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)

Value

A factor

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

Examples

Run this code
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)

Run the code above in your browser using DataLab