rbindlist two data.tables where one has factor and other has character type for a column

后端 未结 3 836
醉话见心
醉话见心 2020-12-09 18:03

I just discovered this warning in my script that was a bit strange.

# Warning message:
# In rbindlist(list(DT.1, DT.2)) : NAs introduced by coercion
         


        
3条回答
  •  忘掉有多难
    2020-12-09 18:10

    The bug is not fixed in R 4.0.2 and data.table 1.13.0. When I try to rbindlist() two DTs, one of which has factor columns, the other one empty, final result gets this column broken, and factor values mangled (\n occuring randomly; levels are broken, NAs are introduced).
    The workaround is to not rbindlisting a DT with an empty one, but instead rbindlist it with other DTs which also has payload data. Although this requires some boilerplate code.

提交回复
热议问题