[datatable-help] probably undesirable function of `rbindlist`
Arunkumar Srinivasan
aragorn168b at gmail.com
Sat Jul 27 21:07:36 CEST 2013
Hi all,
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.
require(data.table)
DT1 <- data.table(x = 1:5, y = 1:5)
x y
1: 1 1
2: 2 2
3: 3 3
4: 4 4
5: 5 5
DT2 <- data.table(x = 6:10, y = 1:5/10)
x y
1: 6 0.1
2: 7 0.2
3: 8 0.3
4: 9 0.4
5: 10 0.5
sapply(DT1, class)
x y
"integer" "integer"
sapply(DT2, class)
x y
"integer" "numeric"
rbindlist(list(DT1, DT2))
x y
1: 1 1
2: 2 2
3: 3 3
4: 4 4
5: 5 5
6: 6 0 <~~~~ from here, the result should be 0.1 to 0.5 for the next 5 rows or y.
7: 7 0
8: 8 0
9: 9 0
10: 10 0
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.
Best,
Arun.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20130727/b100ea92/attachment.html>
More information about the datatable-help
mailing list