Try this:
> V <- data.frame(a = 1:5, b = 1:5, c = 0)
> restriction = "a>1 & b==2 & c<1"
> subset(V, eval(parse(text = restriction)))
a b c
2 2 2 0
Question
Instead of writing for a vector V:
V[a>1 & b==2 & c<1]
I would like something like:
V[restriction]
with
restriction = "a>1 & b==2 & c<1"
Any ideas? Thanks, F.
Solution
Try this:
> V <- data.frame(a = 1:5, b = 1:5, c = 0)
> restriction = "a>1 & b==2 & c<1"
> subset(V, eval(parse(text = restriction)))
a b c
2 2 2 0