Re: [R] Sort a data frame

From: Yves Magliulo <ym_at_climpact.com>
Date: Tue 20 Jul 2004 - 22:35:13 EST

hi,
i had this trouble a while ago and found this function in latest R-help. SortMat <- function(Mat, sort)
{

        m <- do.call("order", as.data.frame(Mat[, Sort]))
        Mat[m, ]

}

where mat is a matrix and sort the column you want to be sorted. convert you dataframe into matrix or change this function to be used with dataframe.

Best,  

Le mar 20/07/2004 Ó 10:51, Luis Rideau Cruz a Úcrit :
> 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@frs.fo
> Web: www.frs.fo
>
> ______________________________________________
> R-help@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

-- 
------
Yves Magliulo <ym@climpact.com>
Climatology research department, CLIMPACT

Tel.   : +33 (0) 1 55 07 85 77
Fax.   : +33 (0) 1 55 07 85 79
Universite Pierre et Marie Curie
Boite 101 - Tour 45 - 5eme etage - Couloir 45/46
4 place Jussieu, 75252 Paris CEDEX 05, France

______________________________________________
R-help@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
Received on Tue Jul 20 22:43:16 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 02:37:13 EST