29

小さな data.table を作成しましDT = data.table(a=1:2, a=1:2)た。

私が使用する場合names(DT) <- c("b","b")

警告が表示されます

In `names<-.data.table`(`*tmp*`, value = c("b", "b")) :
  The names(x)<-value syntax copies the whole table. This is due to <- in R itself. Please change to setnames(x,old,new) which does not copy and is faster. See help('setnames'). You can safely ignore this warning if it is inconvenient to change right now. Setting options(warn=2) turns this warning into an error, so you can then use traceback() to find and change your names<- calls.

しかし、私が使用するsetnames(DT, names(DT), c("b","b")と、エラーが発生します

Error in setnames(DT, names(DT), c("b", "b")) : 
  Some duplicates exist in 'old': a

同じ例が data.frame よりもDT = data.frame(a=1:2, a=1:2)使用 されている場合、names(DT) <- c("b","b")エラーは発生しません。

4

2 に答える 2