> 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 ______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
