[R] How to sort TWO columns ?

TEMPL Matthias Matthias.Templ at statistik.gv.at
Wed Jul 21 09:03:07 CEST 2004


Hi,

It would be discussed yesterday.

See e.g. in Google for ("sorting a data frame" R) http://www.r-project.org/nocvs/mail/r-help/2002/0088.html
Or one entry yesterday:

Best,
Matthias

>Hi

>Lets assign your data frame to the variable yourdf
>then:

>yourdf[ , order( yourdf$year ) ]

>should sort it.

>For decreasing increasing sorting
>see 
>?order

>Sincerely Eryk.



>*********** REPLY SEPARATOR  ***********

>On 20.07.2004 at 09:51 Luis Rideau Cruz wrote:

>Hi all
>
>I have the next data frame
>
>    year   STOD    SLAGNR  TAL TALT   TALVEKT
>1 2002  2120006     57      1      NA      1
>2 1997  97030032    57     NA   NA      NA
>3 1997  97030071    27     1      NA      NA
>4 1997  97030005    57     1      NA      NA
>5 1997  97020127    60     NA   1         NA
>6 2001  1160025     27      1      NA      1
>7 1998  98020069    60     1      NA      NA
>8 1996  96030009    57     NA   1         NA
>
>How to sort it according to "year" column
>Sort does seem to work only on vectors
>
>Thank you
>
>Luis Ridao Cruz
>Fiskirannsóknarstovan
>Nóatún 1
>P.O. Box 3051
>FR-110 Tórshavn
>Faroe Islands
>Phone:             +298 353900
>Phone(direct): +298 353912
>Mobile:             +298 580800
>Fax:                 +298 353901
>E-mail:              luisr at frs.fo
>Web:                www.frs.fo
>

> 
> Dear ALL,
> 
> I fear my question has already been answered many times 
> before, but I haven't fund that in archives...
> 
> I am working on spatial datasets and, in most arrays I'm 
> handling, there are two columns dedicated to (x,y)-coords. 
> For different reasons - notably to draw image() plots, I need 
> to have these two columns sorted in increasing order. But 
> sort() and order() seem to apply to vectors - or one single 
> column - only.
> 
> Could somedy please let me know how to sort two columns of a 
> dataframe, with priority to one of them, just like in access ?
> 
> Thanks,
> 
> Jacques VESLOT
> CIRAD
> 
> Another related question :
> How to put legend on image() plots - or image-based plots like
> image.kriging() in geoR ?
> Despite help pages, I haven't succeeded.
> 
> 
> 
> -----------------------------------------------------
> CIRAD 3P Reunion - MailScanner
> ----------------------------------------------------- 
> Ce message a été vérifié par MailScanner
> et analyse par 4 antivirus :
> ClamAv - BitDefender - F-Prot - Panda.
> 
> Aucun virus,ni rien de suspect n'a été trouvé.
> 
> This message has been scanned for viruses and
> dangerous content, and is believed to be clean.
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list 
> https://www.stat.math.ethz.ch/mailman/listinfo> /r-help
> PLEASE 
> do read the posting guide! 
> http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list