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
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
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
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
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
5 matches
Mail list logo