[datatable-help] Is the (re-)sorting of a data.table by setting itskey stable?

Short, Tom TShort at epri.com
Mon May 3 02:42:32 CEST 2010


Hello Steve, 

It's by design. The sorting/grouping that is done when you set a key is
done internally using either the function "order" or "sort.list" with
the radix option. Both are "stable", meaning that the order of the other
columns is maintained.

- Tom

-----Original Message-----
From: datatable-help-bounces at lists.r-forge.r-project.org
[mailto:datatable-help-bounces at lists.r-forge.r-project.org] On Behalf Of
Steve Lianoglou
Sent: Sunday, May 02, 2010 8:35 PM
To: datatable-help at lists.r-forge.r-project.org
Subject: [datatable-help] Is the (re-)sorting of a data.table by setting
itskey stable?

Hi all,

Firstly, thanks for fixing the bug regarding the non-resorting of a
data.table when it was transformed from a pre-existing data.table. I
just checked out the latest code from SVN and it seems to work as
expected.

Now on to the question:

Say I have a data.frame `gene.annos` like so:

      symbol  exon.start   exon.width   exon.anno
      WASH5P        4225          468         utr
      WASH5P        4833           69         utr
      WASH5P        5659          152         utr
LOC100288778        4225          468         utr
LOC100288778        4833           69         utr
LOC100288778        5659          152         utr
     FAM138F       24475          563         utr
     FAM138F       25140          205         utr
     FAM138F       25584          361         utr

Now say I create a new data.table from the data.frame, and set the
data.table's key to "symbol".

Is it guaranteed for the rows in each "subgroup" be moved around in
the same order as they appeared originally?

For instance, if I did that on this data.table, the information for
"FAM13AF" would be pushed to the top, but would the 1st, 2nd, and 3rd
rows for FAM13AF in the new data.table be the same 1st, 2nd, and 3rd
rows for FAM13AF in the original data.frame?

It looks like it's keeping them in order, but I just wanted to be sure
that this behavior is a guarantee by design, and not a happy
coincidence for now.

Thanks,
-steve

-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact
_______________________________________________
datatable-help mailing list
datatable-help at lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-h
elp


More information about the datatable-help mailing list