Applying a function to each row of a data.table

前端 未结 7 1291
日久生厌
日久生厌 2020-12-03 10:46

I looking for a way to efficiently apply a function to each row of data.table. Let\'s consider the following data table:

library(data.table)
library(stringr)         


        
相关标签:
7条回答
  • 2020-12-03 11:20

    One option would be to add a row number

    x[, r := 1:nrow(x)]
    

    and then group by r:

    x[, list(a, str_split(b, ' ')[[1]]), by = r]
    

    I'm wondering if there are better solutions?

    0 讨论(0)
提交回复
热议问题