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

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to