[datatable-help] cbind doesn't work as expected

Chris Neff caneff at gmail.com
Mon Aug 8 15:48:00 CEST 2011


cbind with a data table and data frame does... something.  I'm not
sure how else I would get these to cbind in quite this way.

> DT <- data.table(x=1:10, y=1:10)
> DT
       x  y
 [1,]  1  1
 [2,]  2  2
 [3,]  3  3
 [4,]  4  4
 [5,]  5  5
 [6,]  6  6
 [7,]  7  7
 [8,]  8  8
 [9,]  9  9
[10,] 10 10
> cbind(DT, data.frame(z=1:10, w=1:10))
  DT
x Integer,10 Integer,10
y Integer,10 Integer,10



Note that doing it with a data.table works fine of course.
> cbind(DT, data.table(z=1:10, w=1:10))
       x  y  z  w
 [1,]  1  1  1  1
 [2,]  2  2  2  2
 [3,]  3  3  3  3
 [4,]  4  4  4  4
 [5,]  5  5  5  5
 [6,]  6  6  6  6
 [7,]  7  7  7  7
 [8,]  8  8  8  8
 [9,]  9  9  9  9
[10,] 10 10 10 10


When cbind'ing a data.table to a data.frame, I think I would expect
the same behavior as doing data.table(DT, data.frame(z=1:10, w=1:10)).
 I may be missing a subtelty there though.

-Chris


More information about the datatable-help mailing list