<div>
Ricardo,
</div><div><br></div><div>Thanks for your reply. Yes, the question comes down to: is it better to retain the type of the first input or the most general input? Even if 1 data.table has a factor input, is it better to retain "factor" instead of "character"? If one of them has a numeric column, then is it better to retain numeric even if the first data.table has integer column?</div><div><br></div><div>And if the first data.table through a division operation yielded integers, then this'll cause an issue, unless one manually typesets. data.table is consistent, alright. But maybe a "warning" or a "message" would be nice.</div>
<div><div><br></div><div>Arun</div><div><br></div></div>
<p style="color: #A0A0A8;">On Sunday, July 28, 2013 at 5:39 AM, Ricardo Saporta wrote:</p>
<blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px;">
<span><div><div><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><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>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 type="cite"><div>
<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></div></blockquote></div><br></div></div>
</div></div></span>
</blockquote>
<div>
<br>
</div>