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

Sorkin, John j@ork|n @end|ng |rom @om@um@ry|@nd@edu
Tue Aug 13 04:20:04 CEST 2019


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]]



More information about the R-help mailing list