row-by-row operations and updates in data.table

前端 未结 4 1175
没有蜡笔的小新
没有蜡笔的小新 2020-12-09 10:39

I ended up with a big data.table and I have to do operations per row. (yes... I know that this is clearly not what data.table are for)

R) set.seed(1)
R) DT=d         


        
4条回答
  •  南方客
    南方客 (楼主)
    2020-12-09 11:41

    This spells out the steps in case you want to use a different function:

    cols    <- names(DT)[grepl('^V[[:digit:]]+$',names(DT))]
    newcols <- c("min","max")
    myfun   <- range
    DT[,(newcols):=as.list(myfun(.SD)),.SDcols=cols,by=1:nrow(DT)]
    

提交回复
热议问题