[R] unexpected subset select results?
David Winsemius
dwinsemius at comcast.net
Tue Aug 24 00:28:10 CEST 2010
On Aug 23, 2010, at 5:51 PM, ivo welch wrote:
> quizz---what does this produce?
>
> d=data.frame( a=1:1000, b=2001:3000, z= 5001:6000 )
> attach(d); c <- (a+b)>25; detach(d)
> d= subset(d, TRUE, select=c( a, b, c ))
>
> yes, I know I have made a mistake, in that the code does not do what I
> presumably would have wanted. it does seem like unexpected behavior,
> though, without an error. there probably is some reason why this does
> not ring an alarm bell...
You have created a perfect example for why it is a bad idea to attach
data.frames.
?attach # yes, I am yet again saying: "read the help page..."
... especially the 4th paragraph of the Details section.
--
David.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list