<div>
This was already addressed here:
</div><div><a href="http://stackoverflow.com/questions/15933846/rbindlist-two-data-tables-where-one-has-factor-and-other-has-character-type-for">http://stackoverflow.com/questions/15933846/rbindlist-two-data-tables-where-one-has-factor-and-other-has-character-type-for</a></div><div><br></div><div>And was known to be a bug filed here:</div><div><a href="https://r-forge.r-project.org/tracker/index.php?func=detail&aid=2650&group_id=240&atid=975">https://r-forge.r-project.org/tracker/index.php?func=detail&aid=2650&group_id=240&atid=975</a></div><div><br></div><div>Which has been fixed in the current development version 1.8.9. (</div><table class="listing full" style="border-collapse: collapse; border-spacing: 0px; font-size: 14px; margin-bottom: 1em; color: rgb(68, 68, 68); font-family: verdana, sans-serif; line-height: 16px; text-align: left; "><tbody><tr class="bgcolor-white" style="background-color: white;"><td style="margin: 0px; padding: 3px; border: none; ">Fixed by commit 879 in v1.8.9</td></tr></tbody></table>
<div><div>Hope this helps,</div><div>Arun</div><div><br></div></div>
<p style="color: #A0A0A8;">On Tuesday, May 21, 2013 at 8:06 PM, Alexandre Sieira wrote:</p>
<blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px;">
<span><div><div><p 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 style="font-family:Helvetica,Arial;font-size:13px; margin: 0px; line-height: auto;"><br></p><p style="margin: 0px; "><font face="Courier New">> dt1 = data.table(a=as.factor(c("a", "a", "a")))</font></p><p style="margin: 0px; "></p><p style="margin: 0px; "><font face="Courier New">> dt1</font></p><p style="margin: 0px; "><font face="Courier New"> a</font></p><p style="margin: 0px; "><font face="Courier New">1: a</font></p><p style="margin: 0px; "><font face="Courier New">2: a</font></p><p style="margin: 0px; "><font face="Courier New">3: a</font></p><p style="margin: 0px; "><font face="Courier New">> str(dt1)</font></p><p style="margin: 0px; "><font face="Courier New">Classes ‘data.table’ and 'data.frame':<span style="white-space:pre"> </span>3 obs. of 1 variable:</font></p><p style="margin: 0px; "><font face="Courier New"> $ a: Factor w/ 1 level "a": 1 1 1</font></p><p style="margin: 0px; "><font face="Courier New"> - attr(*, ".internal.selfref")=<externalptr> </font></p><p style="margin: 0px; "><font face="Courier New">> dt2 = data.table(a=as.factor(c("b", "b", "b")))</font></p><p style="margin: 0px; "><font face="Courier New">> dt2</font></p><p style="margin: 0px; "><font face="Courier New"> a</font></p><p style="margin: 0px; "><font face="Courier New">1: b</font></p><p style="margin: 0px; "><font face="Courier New">2: b</font></p><p style="margin: 0px; "><font face="Courier New">3: b</font></p><p style="margin: 0px; "><font face="Courier New">> str(dt2)</font></p><p style="margin: 0px; "><font face="Courier New">Classes ‘data.table’ and 'data.frame':<span style="white-space:pre"> </span>3 obs. of 1 variable:</font></p><p style="margin: 0px; "><font face="Courier New"> $ a: Factor w/ 1 level "b": 1 1 1</font></p><p style="margin: 0px; "><font face="Courier New"> - attr(*, ".internal.selfref")=<externalptr> </font></p><p style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px; "><br></p><p 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 style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px; "><br></p><p style="margin: 0px; "></p><p style="margin: 0px; "><font face="Courier New">> rbind(dt1, dt2)</font></p><p style="margin: 0px; "><font face="Courier New"> a</font></p><p style="margin: 0px; "><font face="Courier New">1: a</font></p><p style="margin: 0px; "><font face="Courier New">2: a</font></p><p style="margin: 0px; "><font face="Courier New">3: a</font></p><p style="margin: 0px; "><font face="Courier New">4: b</font></p><p style="margin: 0px; "><font face="Courier New">5: b</font></p><p style="margin: 0px; "><font face="Courier New">6: b</font></p><p></p><p style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px; "><br></p><p 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 style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px; "><br></p><p style="margin: 0px; "></p><p style="margin: 0px; "><font face="Courier New">> rbindlist(list(dt1, dt2))</font></p><p style="margin: 0px; "><font face="Courier New"> a</font></p><p style="margin: 0px; "><font face="Courier New">1: a</font></p><p style="margin: 0px; "><font face="Courier New">2: a</font></p><p style="margin: 0px; "><font face="Courier New">3: a</font></p><p style="margin: 0px; "><font face="Courier New">4: a</font></p><p style="margin: 0px; "><font face="Courier New">5: a</font></p><p style="margin: 0px; "><font face="Courier New">6: a</font></p><p style="margin: 0px; "></p><p style="margin: 0px; "><font face="Courier New">> str(rbindlist(list(dt1, dt2)))</font></p><p style="margin: 0px; "><font face="Courier New">Classes ‘data.table’ and 'data.frame':<span style="white-space:pre"> </span>6 obs. of 1 variable:</font></p><p style="margin: 0px; "><font face="Courier New"> $ a: Factor w/ 1 level "a": 1 1 1 1 1 1</font></p><p style="margin: 0px; "><font face="Courier New"> - attr(*, ".internal.selfref")=<externalptr> </font></p><p></p><p style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px; "><br></p><p 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 style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px; "><br></p><p style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px; ">Is this expected behavior? Am I missing something?</p><p></p><p></p><br><div><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></div><div><div>_______________________________________________</div><div>datatable-help mailing list</div><div><a href="mailto:datatable-help@lists.r-forge.r-project.org">datatable-help@lists.r-forge.r-project.org</a></div><div><a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a></div></div></div></span>
</blockquote>
<div>
<br>
</div>