R storing a complex search as a string

Posted by Tahnoon Pasha on Stack Overflow See other posts from Stack Overflow or by Tahnoon Pasha
Published on 2012-12-07T04:46:00Z Indexed on 2012/12/07 5:04 UTC
Read the original article Hit count: 228

Filed under:
|

Hi I'm working with a large data frame that I frequently need to subset in different combinations of variables. I'd like to be able to store the search in a string so I can just refer to the string when I want to see a subset.

x = read.table(textConnection("
                              cat1 cat2 value
                              A     Z    1
                              A     Y    2
                              A     X    3
                              B     N    2"),header=T,strip.white=T)
search_string="cat1== 'A' & cat2=='Z'"
with(x,subset(x,search))

doesn't work. What I'd be looking for is the result of a search similar to the one below.

with(x,subset(x,cat1=='A' & cat2=='Z'))

I'd prefer not to just create multiple subsetted data frames at the start if another solution exists.

Is there a simple way to do what I'm trying?

© Stack Overflow or respective owner

Related posts about r

    Related posts about search