[R] puzzling behavior of within

2013-06-13 Thread Ista Zahn
Hi all, In answering a question yesterday about avoiding repeatedly typing the name of a data.frame when making modifications to it I discovered the following unexpected behavior of within: mtcars - within(mtcars, { x - 0 x[gear==4] - 1 }) generates a column named x in mtcars equal to 1

Re: [R] puzzling behavior of within

2013-06-13 Thread Bert Gunter
Why are you surprised? It has nothing to do with within() . ?[- x - 0 g - 1:2 x[g==1]- 5 x [1] 5 NA -- Bert On Thu, Jun 13, 2013 at 9:00 AM, Ista Zahn istaz...@gmail.com wrote: Hi all, In answering a question yesterday about avoiding repeatedly typing the name of a data.frame when

Re: [R] puzzling behavior of within

2013-06-13 Thread Ista Zahn
On Thu, Jun 13, 2013 at 12:11 PM, Bert Gunter gunter.ber...@gene.com wrote: Why are you surprised? 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

Re: [R] puzzling behavior of within

2013-06-13 Thread Ista Zahn
On Thu, Jun 13, 2013 at 12:17 PM, Ista Zahn istaz...@gmail.com wrote: On Thu, Jun 13, 2013 at 12:11 PM, Bert Gunter gunter.ber...@gene.com wrote: Why are you surprised? Because I missed the significance of examines the environment after the evaluation of 'expr' and makes the corresponding

Re: [R] puzzling behavior of within

2013-06-13 Thread arun
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 istaz...@gmail.com To: Bert Gunter gunter.ber...@gene.com Cc: r-help@r-project.org Sent: Thursday, June 13, 2013 12:17 PM Subject: Re: [R] puzzling behavior