将三个(或更多)data.tables 与 rbind 合并并且两个非空 data.tables 之间有一个空的 data.table 时会发出错误:
> require(data.table)
Loading required package: data.table
data.table 1.9.2 For help type: help("data.table")
> DT <- data.table(x=c(1,2,3))
> rbind(DT, data.table(), DT)
Error in setcolorder(tt, chmatch(match.names, make.names(original.names[[x]], (from <text>#1) :
Column numbers in neworder out of bounds: NA
如果最后是空的 data.table,则不会发生这种情况:
> rbind(DT, DT, data.table())
x
1: 1
2: 2
3: 3
4: 1
5: 2
6: 3
但是当空的 data.table 位于开头时会发生其他一些错误:
> rbind(data.table(), DT, DT)
Error in data.table::.rbind.data.table(...) (from <text>#1) :
Some colnames of argument 2 (x) are not present in colnames of item 1. If an argument has colnames they can be in a different order, but they must all be present. Alternatively, you can supply unnamed lists and they will then be joined by position. Or, set use.names=FALSE.
但是,如果我们只使用两个参数,一切都很好:
> rbind(data.table(), DT)
x
1: 1
2: 2
3: 3
预期的行为应该是什么?