够好了?(不完全是因为列被颠倒了,但setcolorder
如果这是至关重要的话就会完成工作)
dataset[ , {x <- substr(start, 1, 1) s <- as.integer(substr(start, 2, 3)) e <- as.integer(substr(end, 2, 3)) .(code=paste0(x, sprintf("%02d", s:e)))}, by = title]
这是另一种我认为看起来更好但却变得非常混乱的选择:
dataset[, {x<-unlist(lapply( .SD,tstrsplit,split="(?<=[[:alpha:]])",perl=T)) .(code=paste0( x[1],sprintf("%02d",do.call( "seq",as.list(as.integer(x[c(2,4)]))))))}, by=title]