Try this:

subset(x, eval(parse(text=filter)))


On Wed, Jul 8, 2009 at 4:46 PM, Tracey Frescino <tfrescino@fs.fed.us> wrote:

> Hi,
>
> I am trying to subset a dataset based on a filter defined by a user...
> I prompt the user for input.. resulting in a string logical expression
> ("X1 < 3").
>
> I have tried using subset, but it is looking for a logical expression, not
> a character string.
> I keep getting the error:  'subset' must evaluate to logical.
>
>
> Example:
> x <- data.frame(matrix(1:15, nrow=5, ncol=3))
> filter = "X1 < 3"
> subset(x, filter)
>
>
> Any ideas??
>
>
>
> Thanks much,
> Tracey
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

	[[alternative HTML version deleted]]


