[datatable-help] Characters and Factor
Damian Betebenner
dbetebenner at nciea.org
Thu Apr 26 22:50:22 CEST 2012
All,
Not sure how to characterize this (a new feature or a bug) but the behavior is causing problems in code I've written that previously work as I expected. I have integers that are bigger than 2^32 that
I have to encode as factors, after doing some data.table stuff (like below), it recorders the factors as characters and corrupts subsequent merges back to tables where these factors are ordered as
"integers".
Remedies?
tmp.dt1 <- data.table(X=as.factor(1:10), Y=rnorm(10), key="X")
tmp.dt2 <- data.table(X=as.factor(101:110), Y=rnorm(10), key="X")
rbind(tmp.dt1, tmp.dt2)
V1 Y
[1,] 1 0.47655333
[2,] 2 -0.43962704
[3,] 3 -0.78312270
[4,] 4 1.88935392
[5,] 5 -0.56413463
[6,] 6 -0.69177767
[7,] 7 -0.09942112
[8,] 8 0.21452552
[9,] 9 -0.86136222
[10,] 10 0.55623427
[11,] 101 0.02090036
[12,] 102 -0.41816481
[13,] 103 0.04798975
[14,] 104 0.93709966
[15,] 105 -0.95835181
[16,] 106 0.82207890
[17,] 107 0.85902512
[18,] 108 1.33042023
[19,] 109 0.22596849
[20,] 110 0.99209054
data.table(rbind(tmp.dt1, tmp.dt2), key="X")
X Y
[1,] 1 -0.16225884
[2,] 10 0.82979617
[3,] 101 0.22412653
[4,] 102 -0.24841475
[5,] 103 -0.09914182
[6,] 104 -1.47982574
[7,] 105 -1.79957210
[8,] 106 -2.01715940
[9,] 107 -0.81900855
[10,] 108 0.26357249
[11,] 109 -1.22742679
[12,] 110 0.64773494
[13,] 2 -0.98312948
[14,] 3 0.99937771
[15,] 4 -1.72355977
[16,] 5 -2.02481542
[17,] 6 -0.07222688
[18,] 7 0.17921321
[19,] 8 -0.92102526
[20,] 9 -0.14129584
data.table(rbind(tmp.dt1, tmp.dt2), key="X")
Damian Betebenner
Center for Assessment
PO Box 351
Dover, NH 03821-0351
Phone (office): (603) 516-7900
Phone (cell): (857) 234-2474
Fax: (603) 516-7910
dbetebenner at nciea.org<mailto:dbetebenner at nciea.org>
www.nciea.org<http://www.nciea.org/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20120426/7f462277/attachment.html>
More information about the datatable-help
mailing list