Re: [R] concise syntax for selecting multiple rows

2010-04-26 Thread David Winsemius
On Apr 26, 2010, at 11:27 AM, Gabor Grothendieck wrote: Here are four ways: # state.name comes with R DF <- data.frame(state = state.name, num = seq_along(state.name)) DF[DF$state %in% c("Iowa", "Utah"),] subset(DF, state %in% c("Iowa", "Utah")) subset(DF, grepl("Iowa|Utah", state)) John;

Re: [R] concise syntax for selecting multiple rows

2010-04-26 Thread Gabor Grothendieck
Here are four ways: # state.name comes with R DF <- data.frame(state = state.name, num = seq_along(state.name)) DF[DF$state %in% c("Iowa", "Utah"),] subset(DF, state %in% c("Iowa", "Utah")) subset(DF, grepl("Iowa|Utah", state)) library(sqldf) # see http://sqldf.googlecode.com sqldf("select * f

Re: [R] concise syntax for selecting multiple rows

2010-04-26 Thread Erik Iverson
See ?%in% result$Subject %in% c("JEFF", "BG") 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 ro

Re: [R] concise syntax for selecting multiple rows

2010-04-26 Thread David Winsemius
On Apr 26, 2010, at 11: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

Re: [R] concise syntax for selecting multiple rows

2010-04-26 Thread Marc Schwartz
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

[R] concise syntax for selecting multiple rows

2010-04-26 Thread John Sorkin
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"]