<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><p id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; margin: 0px; line-height: auto;">I think I found an unexpected behavior with rbindlist when columns are factors:</p><p id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; margin: 0px; line-height: auto;"><br></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">> dt1 = data.table(a=as.factor(c("a", "a", "a")))</font></p><p id="bloop_customfont" style="margin: 0px; "><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">> dt1</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New"> a</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">1: a</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">2: a</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">3: a</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">> str(dt1)</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">Classes ‘data.table’ and 'data.frame':<span class="Apple-tab-span" style="white-space:pre"> </span>3 obs. of 1 variable:</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New"> $ a: Factor w/ 1 level "a": 1 1 1</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New"> - attr(*, ".internal.selfref")=<externalptr> </font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">> dt2 = data.table(a=as.factor(c("b", "b", "b")))</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">> dt2</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New"> a</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">1: b</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">2: b</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">3: b</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">> str(dt2)</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">Classes ‘data.table’ and 'data.frame':<span class="Apple-tab-span" style="white-space:pre"> </span>3 obs. of 1 variable:</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New"> $ a: Factor w/ 1 level "b": 1 1 1</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New"> - attr(*, ".internal.selfref")=<externalptr> </font></p><p id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px; "><br></p><p id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px; ">If I rbind them, I get the expected value - a table with 6 rows, 3 of which have value "a" and 3 with value "b":</p><p id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px; "><br></p><p id="bloop_customfont" style="margin: 0px; "><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">> rbind(dt1, dt2)</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New"> a</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">1: a</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">2: a</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">3: a</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">4: b</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">5: b</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">6: b</font></p></p><p id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px; "><br></p><p id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px; ">So if I do rbindlist(list(dt1, dt2)), I would expect to get the exact same result, only faster. Unfortunately, that is not the case:</p><p id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px; "><br></p><p id="bloop_customfont" style="margin: 0px; "><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">> rbindlist(list(dt1, dt2))</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New"> a</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">1: a</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">2: a</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">3: a</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">4: a</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">5: a</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">6: a</font></p><p id="bloop_customfont" style="margin: 0px; "><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">> str(rbindlist(list(dt1, dt2)))</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">Classes ‘data.table’ and 'data.frame':<span class="Apple-tab-span" style="white-space:pre"> </span>6 obs. of 1 variable:</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New"> $ a: Factor w/ 1 level "a": 1 1 1 1 1 1</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New"> - attr(*, ".internal.selfref")=<externalptr> </font></p></p><p id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px; "><br></p><p id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px; ">This was executed with R 3.0.1 and data.table 1.8.8 on a Mac OS X 10.8.3.</p><p id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px; "><br></p><p id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px; ">Is this expected behavior? Am I missing something?</p></p></p><br><div id="bloop_sign_1369159164540145920"><span style="font-family:helvetica,arial;font-size:13px"></span><div style="font-family: Helvetica; line-height: normal; ">-- </div><div style="font-family: Helvetica; line-height: normal; "><span style="font-family: arial; font-size: small; ">Alexandre Sieira</span><br style="font-family: arial; font-size: small; "><span style="font-family: arial; font-size: small; ">CISA, CISSP, ISO 27001 Lead Auditor</span><br style="font-family: arial; font-size: small; "><br style="font-family: arial; font-size: small; "><span style="font-family: arial; font-size: small; ">"The truth is rarely pure and never simple."</span><br style="font-family: arial; font-size: small; "><span style="font-family: arial; font-size: small; ">Oscar Wilde, The Importance of Being Earnest, 1895, Act I</span></div></div></body></html>