R storing a complex search as a string
- by Tahnoon Pasha
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?