Displaying 3 results from an estimated 3 matches for "subsetexp".
2010 Jun 26
3
converting result of substitute to 'ordidnary' expression
...n the argument
is 'expression(...)'. The result is a call to the 'expression'
constructor function and needs to be evaluated with 'eval' to give
the actual expression object.
And indeed I am confused. Consider:
> dat <- data.frame(x=1:10, y=1:10)
> subsetexp <- substitute(a<x, list(a=5))
## this doesn't work
> subset(dat, subsetexp)
Error in subset.data.frame(dat, subsetexp) :
'subset' must evaluate to logical
## this does work (thanks to the help page), but one needs to remember to call eval
> subset(dat, eval(subsetexp))...
2010 Jun 26
3
converting result of substitute to 'ordidnary' expression
...n the argument
is 'expression(...)'. The result is a call to the 'expression'
constructor function and needs to be evaluated with 'eval' to give
the actual expression object.
And indeed I am confused. Consider:
> dat <- data.frame(x=1:10, y=1:10)
> subsetexp <- substitute(a<x, list(a=5))
## this doesn't work
> subset(dat, subsetexp)
Error in subset.data.frame(dat, subsetexp) :
'subset' must evaluate to logical
## this does work (thanks to the help page), but one needs to remember to call eval
> subset(dat, eval(subsetexp))...
2010 Jun 26
2
subset arg in subset(). was: converting result of substitute to 'ordidnary' expression
Dear R users,
Please disregard my previous post "converting result of substitute to 'ordidnary' expression". The problem I have has nothing to do with substitute.
Consider:
> dat <- data.frame(x=1:10, y=1:10)
> subsetexp <- expression(5<x)
> ## this does work
> subset(dat, eval(subsetexp))
x y
6 6 6
7 7 7
8 8 8
9 9 9
10 10 10
> ## and so does this
> subset(dat, 5<x)
x y
6 6 6
7 7 7
8 8 8
9 9 9
10 10 10
> ## but this doesn't work
> subset(dat, subse...