On Apr 26, 2010, at 10:12 AM, John Sorkin wrote:

> I would like to select rows if a row contains any one of several values. I 
> can do the selection as follows:
> 
> result[,"Subject"]=="JEFF" | result[,"Subject"]=="BG"
> 
> But this is very unwieldily if one wishes to select many, many rows as one 
> has to continuously repeat the source:
> 
> result[,"Subject"]=="JEFF" | result[,"Subject"]=="BG" | 
> result[,"Subject"]=="John"  |  result[,"Subject"]=="Mary"
> 
> Is there an easier way? I tried the following but it did not work:
> 
> 
> result[,"Subject"]==c("JEFF" | "BG" | "John"  | "Mary")
> 
> Thanks,
> John


John,

Try:

  subset(result, Subject %in% c("JEFF", "BG", "John", "Mary"))


See ?subset and ?"%in%"

HTH,

Marc Schwartz

______________________________________________
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