[R] concise syntax for selecting multiple rows

John Sorkin jsorkin at grecc.umaryland.edu
Mon Apr 26 17:12:30 CEST 2010


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 David Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)

Confidentiality Statement:
This email message, including any attachments, is for th...{{dropped:6}}



More information about the R-help mailing list