Hello I have the following variables, all of which are logicals fmar15 fcoc15 fher15 fcrk15 fidu15 what I would like is a variable drug15 which equals idu if fidu15 is T; crk if fidu15 is F but fcrk is T, her if fher15 is T but fcrk15 and fidu15 are F and so on What's the best way to do this? Thanks in advance Peter L. Flom, PhD Assistant Director, Statistics and Data Analysis Core Center for Drug Use and HIV Research National Development and Research Institutes 71 W. 23rd St www.peterflom.com New York, NY 10010 (212) 845-4485 (voice) (917) 438-0894 (fax)
> I have the following variables, all of which are logicals > > fmar15 fcoc15 fher15 fcrk15 fidu15 > > what I would like is a variable drug15 which equals > idu if fidu15 is T; crk if fidu15 is F but fcrk is T, her if fher15 is > T but fcrk15 and fidu15 are F and so on > > What's the best way to do this? >I don't know about the best way, but if I understand your question, the following achieves what you want:> tab <- cbind(fidu15, fcrk15, fher15, fcoc15, fmar15) > substring(colnames(tab), 2, 4)[apply(tab, 1, match, x = T)]HTH Ray Brownrigg