Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

Creating new conditioned factor variable from multiple binary variables in R

$
0
0

I need to make a new 3-level categorical variable that reflects whether a subject died of a certain class of drug in an overdose. The levels would be something like: "Class A only", "Class B only", "Class A + Class B".

Within the data frame, there are numerous (about 90) different individual drugs variables that are binary variables (0/1) which indicate if that drug was found in the subject's toxicology. What I would need to do is find a way to create this new factor variable that would tell us if one of the, say 25, drugs that are of Class A were found in that individual subject and then assign the new factor variable a value of "Class A" or "Class A + Class B" depending if a Class B drug was also present.

I'm overwhelmed with where to start. Any suggestions?


Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>