如何让R读取字符串作为限制?

时间:2013-12-20 01:20:02

标签: string r restriction

而不是为矢量V写:

V[a>1 & b==2 & c<1]

我想要像:

V[restriction]

restriction = "a>1 & b==2 & c<1"

有什么想法吗? 谢谢, F。

1 个答案:

答案 0 :(得分:1)

试试这个:

> 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