[datatable-help] Setting key when resulting order of table is not unique

Alexander Peterhansl APeterhansl at GAINCapital.com
Thu Jul 21 17:02:50 CEST 2011


Dear Data Table Help List,

I am using data.table version 1.6 (with R version 2.12.2, 64-bit on Windows 7).  Suppose I have a table whose key does not give me a unique ordering.  Then the output of the "roll" option will be arbitrary (i.e., it will depend on what one does between the two executions).  Is this something noteworthy?

Please see output of the following:
> DT = data.table(A=c(1,2,2),B=c("b1","b3","b2"),key="A")
> DT[J(1:3),roll=TRUE]  # output 1
        A  B
[1,] 1 b1
[2,] 2 b3
[3,] 2 b2
[4,] 3 b2

> key(DT)="B"           # change keys to do other stuff...
> key(DT)="A"           # get back to key A

> DT[J(1:3),roll=TRUE]  # output 2 does not match output 1
        A  B
[1,] 1 b1
[2,] 2 b2
[3,] 2 b3
[4,] 3 b3

(Also, as an aside, I get identical output in the two executions of DT[J(1:3),roll=TRUE] when I start with the table DT = data.table(A=c(1,2,2),B=c("b1","b2","b3"),key="A") instead.)

I'm sure there must also be other reverberations-beyond the effect on the roll option.

Any insight would be of interest.  Thank you.

-Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20110721/908293b5/attachment.htm>


More information about the datatable-help mailing list