[R] Control the variable order after multiple declarations using within
Jeff Newmiller
jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
Wed Jul 3 14:45:00 CEST 2019
I have found using `with` to create one column at a time to be more clear than using `within` when sticking with base R, though I don't see why `within` couldn't be repaired to behave more like `mutate`.
On July 3, 2019 5:24:14 AM PDT, Sebastien Bihorel <sebastien.bihorel using cognigencorp.com> wrote:
>Hi Kevin,
>
>I was hoping to stay within base R functionality.
>
>Thanks
>
>----- Original Message -----
>From: "Kevin Thorpe" <kevin.thorpe using utoronto.ca>
>To: "Sebastien Bihorel" <sebastien.bihorel using cognigencorp.com>
>Cc: "R Help Mailing List" <r-help using r-project.org>
>Sent: Wednesday, July 3, 2019 8:11:51 AM
>Subject: Re: [R] Control the variable order after multiple declarations
>using within
>
>> On Jul 3, 2019, at 3:15 AM, Sebastien Bihorel
><sebastien.bihorel using cognigencorp.com> wrote:
>>
>> 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)?
>>
>
>One way is to use mutate() from the dplyr package.
>
>
>> Thanks
>>
>> Sebastien
>>
>> ______________________________________________
>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.
--
Sent from my phone. Please excuse my brevity.
More information about the R-help
mailing list