Fast melted data.table operations

前端 未结 3 1491
孤城傲影
孤城傲影 2021-01-05 04:50

I am looking for patterns for manipulating data.table objects whose structure resembles that of dataframes created with melt from the reshape

3条回答
  •  长情又很酷
    2021-01-05 05:41

    I'm not sure if this is the best way, but you can try:

    input[, list(x = sum(value[variable == "x"]), 
                 y = sum(value[variable == "y"])), by = "id"]
    #    id  x  y
    # 1:  1  1  5
    # 2:  2  4 11
    # 3:  3 15  9
    

提交回复
热议问题