[R] sorting rows of dataframe

David Winsemius dwinsemius at comcast.net
Wed May 12 06:29:28 CEST 2010


On May 11, 2010, at 10:44 PM, michael westphal wrote:

> Hello:
>
> I have a dataframe, where the first column in a month:
>
> Month CATCHMENT_      med        min      max
> 1    Apr   Alknda01 71.68080 11.9406600 196.2753
> 2    Apr   Alknda02 69.44580 12.1065600 196.2753
> 3    Apr  ArialKhan 39.89310  5.8598700 175.4433
> 4    Apr    Arjun01  4.79652  0.0093336  55.7136
> 5    Apr    Arjun02  4.79652  0.0093336  55.7136
> 6    Apr     Arun01 52.42320  0.1571928 241.9566
> 7    Apr     Arun02 31.05060  0.1738902 420.6930
> 8    Apr    Atrai01 52.58640  2.2828830 190.8891
> 9    Apr    Atrai02 51.98850  2.6499780 189.7872
> 10   Apr    Babai01 27.55440  0.0332469 130.7787
>
>
> I want to sort the rows by Month, not alphabetically, but in the  
> calendar order.  Any suggestions?
>

?LETTERS  # cuz that where month.abb is documented.

Perhaps:

dfrm$Month <- factor(dfrm$Month, levels=month.abb)
dfrm[ order(dfrm$Month), ]


-- 
David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list