[R] Trying to understand how to sort a DF on two columns

Jeff Newmiller jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
Tue Aug 13 06:51:15 CEST 2019


With this as an example, no wonder you don't understand it. This is horrible.

`with` is very much like the `subset` function... it alleviates the need to re-type the containing object name repeatedly.

data4xsort <- temp[ with( temp, order( patid, time ) ), ]

is the same as

data4xsort <- temp[ order( temp$patid, temp$time ), ]

The example you gave makes no use of the `with` function.

On August 12, 2019 7:44:29 PM PDT, "Sorkin, John" <jsorkin using som.umaryland.edu> wrote:
>Bert,
>
>Thank you for your reply (and the many other questions to the list that
>you answer).
>
>I understand how order works when ordering based on a single column.
>What I don’t understand is how the code I included with my email works.
>I believe my problem is a lack of understanding of what with does. I
>have read about the with function, but I must be missing something.
>
>Thank you,
>John
>
>From: Bert Gunter <bgunter.4567 using gmail.com>
>Sent: Monday, August 12, 2019 10:36 PM
>To: Sorkin, John <jsorkin using som.umaryland.edu>
>Cc: r-help using r-project.org (r-help using r-project.org) <r-help using r-project.org>
>Subject: Re: [R] Trying to understand how to sort a DF on two columns
>
>https://stackoverflow.com/questions/2315601/understanding-the-order-function
>
>Do a web search on "How does order() work R" or similar for more.
>
>I can't explain with() any better than the docs: saying that it
>evaluates the expression argument in the data argument environment -- a
>data frame for the data frame method -- probably won't help you.
>
>-- Bert
>
>Bert Gunter
>
>"The trouble with having an open mind is that people keep coming along
>and sticking things into it."
>-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
>On Mon, Aug 12, 2019 at 7:20 PM Sorkin, John
><jsorkin using som.umaryland.edu<mailto:jsorkin using som.umaryland.edu>> wrote:
>I want to sort a DF, temp, on two columns, patid and time. I have
>searched the internet and found code that I was able to modify to get
>my data sorted. Unfortunately I don't understand how the code works. I
>would appreciate it if someone could explain to me how the code works.
>Among other questions, despite reading, I don't understand how with()
>works, nor what it does in the current setting.
>
>code:
>data4xsort<-temp[
>  with( temp, order(temp[,"patid"], temp[,"time"])),
>]
>
>Thank you,
>John
>
>
>
>
>
>John David Sorkin M.D., Ph.D.
>Professor of Medicine
>Chief, Biostatistics and Informatics
>University of Maryland School of Medicine Division of Gerontology and
>Geriatric Medicine
>Baltimore VA Medical Center
>10 North Greene Street
>GRECC (BT/18/GR)
>Baltimore, MD 21201-1524
>(Phone) 410-605-7119
>(Fax) 410-605-7913 (Please call phone number above prior to faxing)
>
>
>        [[alternative HTML version deleted]]
>
>______________________________________________
>R-help using r-project.org<mailto: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.
>
>	[[alternative HTML version deleted]]
>
>______________________________________________
>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