[R] Sorting a data frame
Duncan Murdoch
dmurdoch at pair.com
Wed Jul 16 16:44:05 CEST 2003
On Wed, 16 Jul 2003 14:42:09 +0100, Wayne Jones <JonesW at kssg.com>
wrote :
>
>Hi there R-Helpers,
>
>Does anyone know if it is possible to sort a dataframe?
>
>I.e. Sort alphabetically column 1 ( which has some reocurring elements) then
>sort alphabetically column2 but keeping the order of column 1 constant;
>much the same way that the sort function works in Excel.
The general idea is to use order():
sorted <- unsorted[order(unsorted$col1, unsorted$col2),]
Duncan Murdoch
More information about the R-help
mailing list