Domanda

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.

È stato utile?

Soluzione

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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top