[R] Problem with multy level sorting

David Winsemius dwinsemius at comcast.net
Fri Jan 29 16:00:44 CET 2010


On Jan 29, 2010, at 9:34 AM, venkata kirankumar wrote:

> Hi all
> I have a dataframe like I coppied below
>
>
>> ff
>       a      b      d
> 1    10     5       7
> 2    20     4       9
> 3     3     8       10
> 4     5     6        8
> 5     6     3        5
> 6    73    7        3
> 7    45    28      9
> 8    3      2       8
>
> while I am trying to sort multy coloums  at once I am not able to  
> get that
> like ina order of   first column "a" next column "d" after that  
> column "b"
> here I tried with
>
>
> o <- order(a,d,b)

a, b and d are not objects. They are columns within ff.

  with( ff, order(a,b,d))
#[1] 8 3 4 5 1 2 7 6

> but it returns an error
> can any one help me to sort this multy-columns atonce

The ordering of that dataframe would be (almost) uniquely determined  
by ordering on the first column. Even the one duplicate (3) gets  
resolved with reference to the second column.

ff[with(ff, order(a,b,d)), ]

    a  b  d
8  3  2  8
3  3  8 10
4  5  6  8
5  6  3  5
1 10  5  7
2 20  4  9
7 45 28  9
6 73  7  3


>
>
> thanks in advance
>
> kiran
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT



More information about the R-help mailing list