[R] Recoding problem
Ray Brownrigg
ray at mcs.vuw.ac.nz
Mon Dec 8 21:23:49 CET 2003
> 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
More information about the R-help
mailing list