[R] Using a string as a filter

Gabor Grothendieck ggrothendieck at gmail.com
Sun Jul 10 14:49:42 CEST 2005


On 7/10/05, Yzhar Toren <torenizh at post.tau.ac.il> wrote:
> Hi ,
> 
> I want to be able to filter out results using a string. I'm running an
> automated script that reads a list of filters I get from an external
> source and applys them to my data frame consecutively.
> 
> For example I want to get : data[protocol==1], data[protocol==2] ...
> 
> If I define
> filter1 <- "protocol==1" (as a string)
> filter2 <- "protocol==2"
> ...

protocol <- 1:5
data <- 11:15
filter <- "protocol==1"
data[eval(parse(text=filter))] # 11




More information about the R-help mailing list