ms_flatten {rimu} | R Documentation |
Flatten a scored multiple-response object into a factor
Description
Convert a multiple-response object into a named numeric vector using a supplied ordering.
Usage
ms_flatten(x, priorities, fun, start=0)
Arguments
x |
|
priorities |
Character vector of levels. |
fun |
Function for reducing two values to one. |
start |
starting value for |
Details
Each observation is initially assigned the value start
. Starting with the lowest-priority level, the current value is combined with the new value as fun(new, current)
. Using fun=function(x,y) x
would return the value for the highest-priority level present; using fun=pmax
would return the highest score for any level present; using fun="+"
would return the sum of the scores.
Value
A factor
Examples
data(ethnicity)
ethnicity
## NZ 'prioritised ethnicity'
eth <- mr_recode(ethnicity, `European/Other`="European", `European/Other` = "MELAA")
mr_flatten(ethnicity, c("Maori","Pacific","Asian","European/Other"))
data(nzbirds)
## hardest to see first
ms_flatten(nzbirds, c("kaki","ruru","kea","tui","tauhou"),"+")
ms_flatten(nzbirds, c("kaki","ruru","kea","tui","tauhou"),
fun=function(x,y) x)
ms_flatten(nzbirds, c("kaki","ruru","kea","tui","tauhou"),pmin,start=Inf)
[Package rimu version 0.6 Index]