[R] How do you test if a number is in a list of numbers?
JustinNabble
justinmmcgrath at hotmail.com
Sun Oct 11 08:13:12 CEST 2009
Hi,
I want to subset a data frame if one of the variables matches any in a list.
I could of course do something like this:
subset(dataset, var == 1 | var == 2 | var ==3)
but that's tedious.
I tried
varlist = c(1,2,3,4)
subset(dataset, any(var == varlist))
but it doesn't work because 'any' doesn't go row-by-row and hence always
returns TRUE.
Is there any simple way to do this?
Justin
--
View this message in context: http://www.nabble.com/How-do-you-test-if-a-number-is-in-a-list-of-numbers--tp25840964p25840964.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list