I have a dataframe with four logical vectors, v1, v2, v3, v4 that are TRUE or FALSE. I need to classify each row of the dataframe based on the combination of the boolean vectors (for example, “None”, “v1 only”, “v1 and v3”, “All”, etc.). I would like to do this without taking a subset of the dataframe or nesting ifelse statements.
Any suggestions for the best way to do this? Thanks!
I have a dataframe with four logical vectors, v1 , v2 , v3 ,
Share
Looks like I’ve arrived late at this party. Still, I might as well share what I’ve brought!
This works by treating the
FALSE/TRUEpossibilities like bits, and operating on them to assign to each combination ofv1,v2, andv3a unique integer between 1 and 8 (much likechmodcan represent permission bits on*NIXsystems). The integer is then used as an index to select the appropriate element of a vector of textual descriptors.(For the demonstration, I’ve used just three columns, but this approach scales up nicely.)