Vadim Ogranovich
2010-Jun-26 01:12 UTC
[R] 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, subsetexp)Error in subset.data.frame(dat, subsetexp) : 'subset' must evaluate to logical Why did the last expression fail and why it worked with eval()? Thank you very much for your help, Vadim Note: This email is for the confidential use of the named addressee(s) only and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you are hereby notified that any review, dissemination or copying of this email is strictly prohibited, and to please notify the sender immediately and destroy this email and any attachments. Email transmission cannot be guaranteed to be secure or error-free. Jump Trading, therefore, does not make any guarantees as to the completeness or accuracy of this email or any attachments. This email is for informational purposes only and does not constitute a recommendation, offer, request or solicitation of any kind to buy, sell, subscribe, redeem or perform any type of transaction of a financial product.
Dennis Murphy
2010-Jun-26 04:39 UTC
[R] subset arg in subset(). was: converting result of substitute to 'ordidnary' expression
Hi: On Fri, Jun 25, 2010 at 6:12 PM, Vadim Ogranovich < vogranovich@jumptrading.com> wrote:> 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) >> class(subsetexp)[1] "expression"> > ## this does work > > subset(dat, eval(subsetexp)) > x y > 6 6 6 > 7 7 7 > 8 8 8 > 9 9 9 > 10 10 10 > > eval(subsetexp)[1] FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE> > > > ## 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 >> 5 < x[1] FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE> > > ## but this doesn't work > > subset(dat, subsetexp) > Error in subset.data.frame(dat, subsetexp) : > 'subset' must evaluate to logical >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^> > Why did the last expression fail and why it worked with eval()? >subsetexp is an object of class expression, whereas the second argument of subset() expects a logical [vector]. As shown above, both 5 < x and eval(subsetexp) evaluate to logical vectors. HTH, Dennis> > Thank you very much for your help, > Vadim > > Note: This email is for the confidential use of the named addressee(s) only > and may contain proprietary, confidential or privileged information. If you > are not the intended recipient, you are hereby notified that any review, > dissemination or copying of this email is strictly prohibited, and to please > notify the sender immediately and destroy this email and any attachments. > Email transmission cannot be guaranteed to be secure or error-free. Jump > Trading, therefore, does not make any guarantees as to the completeness or > accuracy of this email or any attachments. This email is for informational > purposes only and does not constitute a recommendation, offer, request or > solicitation of any kind to buy, sell, subscribe, redeem or perform any type > of transaction of a financial product. > > ______________________________________________ > 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. >[[alternative HTML version deleted]]
Bill.Venables at csiro.au
2010-Jun-26 06:08 UTC
[R] subset arg in subset(). was: converting result of substitute to 'ordidnary' expression
Here is another one that works:> do.call(subset, list(dat, subsetexp))x y 6 6 6 7 7 7 8 8 8 9 9 9 10 10 10>-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Vadim Ogranovich Sent: Saturday, 26 June 2010 11:13 AM To: 'r-help at r-project.org' Subject: [R] 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, subsetexp)Error in subset.data.frame(dat, subsetexp) : 'subset' must evaluate to logical Why did the last expression fail and why it worked with eval()? Thank you very much for your help, Vadim Note: This email is for the confidential use of the named addressee(s) only and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you are hereby notified that any review, dissemination or copying of this email is strictly prohibited, and to please notify the sender immediately and destroy this email and any attachments. Email transmission cannot be guaranteed to be secure or error-free. Jump Trading, therefore, does not make any guarantees as to the completeness or accuracy of this email or any attachments. This email is for informational purposes only and does not constitute a recommendation, offer, request or solicitation of any kind to buy, sell, subscribe, redeem or perform any type of transaction of a financial product. ______________________________________________ R-help at 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.