[R] Control the variable order after multiple declarations using within

Sebastien Bihorel @eb@@t|en@b|hore| @end|ng |rom cogn|gencorp@com
Wed Jul 3 09:15:19 CEST 2019


Hi, 

The within function can be used to modify data.frames (among other objects). One can even provide multiple expressions to modify the data.frame by more than one expression. However, when new variables are created, they seem to be inserted in the data.frame in the opposite order they were declared: 

> df <- data.frame(a=1) 
> within(df, {b<-a*2; c<-b*3})
  a c b
1 1 6 2 

Is there a way to insert the variables in an order consistent with the order of declaration (ie, a, b, c)? 

Thanks 

Sebastien



More information about the R-help mailing list