R Dynamically build “list” in data.table (or ddply)

后端 未结 4 1743
野的像风
野的像风 2020-12-10 04:29

My aggregation needs vary among columns / data.frames. I would like to pass the \"list\" argument to the data.table dynamically.

As a minimal example:



        
4条回答
  •  粉色の甜心
    2020-12-10 04:40

    Another method (supporting the use of paste or paste0 to build the expression):

    expr <- parse(text=mylist)
    DT[, eval( expr ), by=type]
    #-------
        type lengtha      maxb     meanc
    1: hello       3 0.8265407 0.5244094
    2:   bye       3 0.4955301 0.6289475
    3:    ok       3 0.9527455 0.5600915
    

提交回复
热议问题