Skip to content
Prev 325335 / 398503 Next

puzzling behavior of within

within(mtcars,{ x<-rep(0,nrow(mtcars));x[gear==4]<-1;x[gear==3]<-2}) #should fix this;
A.K.



----- Original Message -----
From: Ista Zahn <istazahn at gmail.com>
To: Bert Gunter <gunter.berton at gene.com>
Cc: r-help at r-project.org
Sent: Thursday, June 13, 2013 12:17 PM
Subject: Re: [R] puzzling behavior of within
On Thu, Jun 13, 2013 at 12:11 PM, Bert Gunter <gunter.berton at gene.com> wrote:
Because I missed the significance of "examines the environment after
the evaluation of 'expr' and makes the corresponding modifications to
'data'" in ?within, and thought my example should be equivalent to

mtcars <- within(mtcars, {
? ? x <- 0
? ? x[gear==4] <- 1
})


It has nothing to do with within() . ?"[<-"
Thanks Bert. Makes me feel stupid, but I guess that's the price I pay
for enlightenment.

Best,
Ista
______________________________________________
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.