Skip to content

cbind of zero-row data.table with empty data.table messes up columns #3445

@mb706

Description

@mb706

I would expect cbind(data.table(), dt[0]) to equal dt[0], but the operation seems to give a broken result with an added column V1 and shifted column types. Note how Species becomes NULL and Petal.Width ends up being a "Factor w/ 3 levels".

> dt <- as.data.table(iris)
> str(cbind(data.table(), dt[0]))
Classesdata.tableand 'data.frame':  0 obs. of  6 variables:
 $ V1          : num 
 $ Sepal.Length: num 
 $ Sepal.Width : num 
 $ Petal.Length: num 
 $ Petal.Width : Factor w/ 3 levels "setosa","versicolor",..: 
 $ Species     : NULL
 - attr(*, ".internal.selfref")=<externalptr> 

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions