<div dir="ltr">Arun, <div><br></div><div>Im pretty sure `rbindlist` identifies column class based on the first argument. </div><div><br></div><div>compare </div><div><div> rbindlist(list(DT2, DT1))</div></div><div><div>
rbindlist(list(DT1, DT2))</div></div><div><br></div><div><br></div><div>I agree with you though that a more ideal behavior would be one that mimics `c( )`</div><div><br></div><div class="gmail_extra"><div><div style="color:rgb(34,34,34);background-color:rgb(255,255,255)">
<div style="font-family:arial,sans-serif;font-size:13px"><br></div>-Rick</div></div>
<br><br><div class="gmail_quote">On Sat, Jul 27, 2013 at 3:07 PM, Arunkumar Srinivasan <span dir="ltr"><<a href="mailto:aragorn168b@gmail.com" target="_blank">aragorn168b@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>
Hi all,
</div><div><br></div><div>Here's a behaviour of `rbindlist` that I came across that I think is undesirable. If the columns to be "rbind" are of type "integer" and "numeric", then, the class "integer" is retained which results in different results than intended.</div>
<div><br></div><div>require(data.table)</div><div>DT1 <- data.table(x = 1:5, y = 1:5)</div><div><div> x y</div><div>1: 1 1</div><div>2: 2 2</div><div>3: 3 3</div><div>4: 4 4</div><div>5: 5 5</div></div><div><br></div>
<div>DT2 <- data.table(x = 6:10, y = 1:5/10)</div><div><div> x y</div><div>1: 6 0.1</div><div>2: 7 0.2</div><div>3: 8 0.3</div><div>4: 9 0.4</div><div>5: 10 0.5</div></div><div><br></div><div>sapply(DT1, class)</div>
<div><div> x y </div><div>"integer" "integer" </div></div><div><br></div><div>sapply(DT2, class)</div><div><div> x y </div><div>"integer" "numeric" </div>
</div><div><br></div><div>rbindlist(list(DT1, DT2))</div>
<div><div><div> x y</div><div> 1: 1 1</div><div> 2: 2 2</div><div> 3: 3 3</div><div> 4: 4 4</div><div> 5: 5 5</div><div> 6: 6 0 <~~~~ from here, the result should be 0.1 to 0.5 for the next 5 rows or y.</div>
<div> 7: 7 0</div><div> 8: 8 0</div><div> 9: 9 0</div><div>10: 10 0</div></div><div><br></div><div>Is this behaviour unexpected or we've to manually take care of this? Seems more proper to be taken care of internally to me though.</div>
<div><br></div><div>Best,</div><div>Arun.</div><div><br></div></div>
<br>_______________________________________________<br>
datatable-help mailing list<br>
<a href="mailto:datatable-help@lists.r-forge.r-project.org">datatable-help@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a><br></blockquote></div><br></div></div>