martin.lenze@web.de
2004-Jun-04 12:04 UTC
[Rd] subset: evaluating expressions missing? (PR#6937)
Full_Name: Martin Lenze Version: Version 1.9.0 (2004-04-12), ISBN 3-900051-00-3 OS: Microsoft Windows 2000 [Version 5.00.2195] SP4 Submission from: (NULL) (82.83.167.79) Hello, now I switched to R 1.9.0 and did get a problem with subset, see sample: x <- data.frame(a=as.integer(round(runif(5),0)), b=as.integer(round(runif(5),0)),c=as.integer(round(runif(5),0))) # correct results: for (c in c(expression(x$a==1),expression(x$b==1), expression(x$c==1))) print(x[eval(c),]) # results I don't understand: for (c in c(expression(x$a==1),expression(x$b==1), expression(x$c==1))) print(subset(x,eval(c))) for (c in c(expression(x$a==1),expression(x$b==1), expression(x$c==1))) print(subset(x,c)) Am I doing something wrong? Using subset this way with R 1.8.0 worked fine. Many thanks in advance Martin Lenze
Prof Brian Ripley
2004-Jun-04 15:40 UTC
[Rd] subset: evaluating expressions missing? (PR#6937)
You should not use the system object `c' as an index! BTW, expression() takes multiple arguments, so you can do # OK for (c2 in expression(x$a==1, x$b==1, x$c==1)) print(x[eval(c2),]) for (c2 in expression(x$a==1, x$b==1, x$c==1)) print(subset(x, eval(c2))) # error, correctly for (c2 in expression(x$a==1, x$b==1, x$c==1)) print(subset(x,c2)) Error in r & !is.na(r) : operations are possible only for numeric or logical types In addition: Warning message: is.na() applied to non-(list or vector) in: is.na(r) On Fri, 4 Jun 2004 martin.lenze@web.de wrote:> Full_Name: Martin Lenze > Version: Version 1.9.0 (2004-04-12), ISBN 3-900051-00-3 > OS: Microsoft Windows 2000 [Version 5.00.2195] SP4 > Submission from: (NULL) (82.83.167.79)> now I switched to R 1.9.0 and did get a problem with subset, see sample: > > x <- data.frame(a=as.integer(round(runif(5),0)), > b=as.integer(round(runif(5),0)),c=as.integer(round(runif(5),0))) > # correct results: > for (c in c(expression(x$a==1),expression(x$b==1), > expression(x$c==1))) print(x[eval(c),]) > # results I don't understand: > for (c in c(expression(x$a==1),expression(x$b==1), > expression(x$c==1))) print(subset(x,eval(c))) > for (c in c(expression(x$a==1),expression(x$b==1), > expression(x$c==1))) print(subset(x,c)) > > Am I doing something wrong? Using subset this way with R 1.8.0 worked fine.Not for me! I get the same wrong results as in 1.9.0 with your code. -- Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Dear all,
Can I make two suggestions regarding help pages.
1) Reflect the current package version on the help pages. Example
truehist {MASS v7.1-14} or truehist {MASS}{7.1-14}
2) Put all of the help.start() pages online like www.perldoc.com. I
realise that there exists
http://www.maths.lth.se/help/R/.R/doc/html/index.html
http://stat.ethz.ch/R-manual/R-patched/doc/html/index.html
and few others but it would be nice to have it on an official page or
linked from it. It would also be nice to have these pages updated
automatically everytime there is new package or new version release.
Of course 2) may create some confusion if the package version that the
help page was based on is different from the installed version, which is
why 1) should be considered as well.
Thanks. Hope this helps,
--
Adaikalavan Ramasamy <ramasamy@cancer.org.uk>
Cancer Research UK