Re: [S-News] Sorting by one variable of a dataframe

Sucharita Ghosh (rita.ghosh@wsl.ch)
Thu, 5 Feb 1998 13:20:35 +0100


The following works on a matrix as well as on a dataframe.

The dataframe X has three variables:
V1 V2 V3
1 2 20 30
2 1 19 34
3 3 21 29

To sort X by the first variable, try X[order(X[,1]),] which gives

V1 V2 V3
2 1 19 34
1 2 20 30
3 3 21 29

>I have a dataframe with 3 variables - time, status and drug. Does anybody
>know how to sort the data
>frame by the time variable, whilst keeping with the time the attributes
>status and drug? As far as I can
>see the sort function only sorts a vector, hence the attributes status and
>drug will stay as they are
>using this.
>
>Any help is greatly appreciated.
>
>Paul Monaghan, University of Liverpool, England.
>-----------------------------------------------------------------------
>This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
>send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
>message: unsubscribe s-news

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news