[R] a better method than a long expression with many OR clauses
Christopher W Ryan
cryan at binghamton.edu
Tue Dec 17 20:13:53 CET 2013
dd <- data.frame(longVariableName1=sample(1:4, 10, replace=TRUE),
longVariableName2=sample(1:4, 10, replace=TRUE))
dd
# define who is a case and who is not
transform(dd, case=(longVariableName1==3 | longVariableName2==3))
But in reality I have 9 of those longVariableName variables,
all of this pattern: alphaCauseX, where X is an integer 1:9.
For any given observation, if any of them == 3, then case=TRUE
Is there a shorter or more elegant way of doing this than
typing out that long string of 9 OR clauses?
I read about any(), but couldn't quite make that do what I want. Maybe
I was using it wrong.
Thanks.
--Chris Ryan
More information about the R-help
mailing list