[R] Sort a data frame

Dimitris Rizopoulos dimitris.rizopoulos at med.kuleuven.ac.be
Tue Jul 20 10:56:23 CEST 2004


Hi Luis,

you could try something like,

data[order(data$year),]

I hope this helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Doctoral Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/396887
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
     http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm


----- Original Message ----- 
From: "Luis Rideau Cruz" <Luisr at frs.fo>
To: <r-help at stat.math.ethz.ch>
Sent: Tuesday, July 20, 2004 10:51 AM
Subject: [R] Sort a data frame


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