I think this does the trick and is about 5x faster.
setkey(DT, fcombined)
DT[DT[, data.table(fcombined = levels(fcombined),
do.call(rbind, strsplit(levels(fcombined), "_")))]]
I split the levels and then simply merged that result back into the original data.table
.
Btw, in my tests strsplit
was about 2x faster (for this task) than the stringr
function.