[R] how to sort a data.frame by ascending some columns

Benilton Carvalho bcarvalh at jhsph.edu
Sun Nov 18 19:59:42 CET 2007


actually,

clones.info[order(clones.info$CHROMOSOME, clones.info$KB_POSITION),]

btw, documented in the help file.
b

On Nov 18, 2007, at 1:54 PM, Henrique Dallazuanna wrote:

> clones.info[order(clones.info$CHROMOSOME),]
>
> --  
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
>
>
> On 18/11/2007, affy snp <affysnp at gmail.com> wrote:
>> Dear list,
>>
>> I have a data frame (238304 rows and 6 columns). I want the data  
>> frame
>> sorted by two columns in ascending order. I am showing
>> the first 5 rows of the data frame
>>
>>> clones.info[1:5,1:6]
>> USER_CLONE_ID  CHROMOSOME  Expr1002  KB_POSITION  Allele_A  WELL_ID
>> 1 SNP_A-1855402 17 41419603 41419603 C rs17572851
>> 2 SNP_A-4249904 17 41420045 41420045 A rs17572893
>> 3 SNP_A-2174835 18 41407760 41407760 C rs17651213
>> 4 SNP_A-1880271 18 41173993 41173993 A rs17563827
>> 5 SNP_A-2313232 17 41169023 41169023 C rs17563787
>>
>> Especially, I want the data frame sorted by column CHROMOSOME
>> first and then by KB_POSITION. Both in ascending orders.
>>
>> So after sorting, it should looks like:
>>> clones.info[1:5,1:6]
>> USER_CLONE_ID  CHROMOSOME  Expr1002  KB_POSITION  Allele_A  WELL_ID
>> 1 SNP_A-2313232 17 41169023 41169023 C rs17563787
>> 2 SNP_A-1855402 17 41419603 41419603 C rs17572851
>> 3 SNP_A-4249904 17 41420045 41420045 A rs17572893
>> 4 SNP_A-1880271 18 41173993 41173993 A rs17563827
>> 5 SNP_A-2174835 18 41407760 41407760 C rs17651213
>>
>> I looked at the R manual and found order() can be used to sort a
>> vector or data frame but only for one vector. Is it possible to
>> sort by two columns using order() or some other functions in
>> R?
>>
>> Thanks a lot!
>>       Allen
>>
>>        [[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.
>>
>
> ______________________________________________
> 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.



More information about the R-help mailing list