can the value.var in dcast be a list or have multiple value variables?

前端 未结 3 1115
醉酒成梦
醉酒成梦 2020-12-01 06:16

In the help files for dcast.data.table, there is a note stating that a new feature has been implemented: \"dcast.data.table allows value.var column to be of typ

3条回答
  •  情深已故
    2020-12-01 06:59

    From v1.9.6 of data.table, we can cast multiple value.var columns simultaneously (and also use multiple aggregation functions in fun.aggregate). Please see ?dcast and the Efficient reshaping using data.tables vignette for more.

    Here's how we could use dcast:

    dcast(setDT(mydf), x1 ~ x2, value.var=c("salt", "sugar"))
    #    x1 salt_1 salt_2 salt_3 sugar_1 sugar_2 sugar_3
    # 1:  1      3      4      6       1       2       2
    # 2:  2     10      3      9       5       3       6
    # 3:  3     10      7      7       4       6       7
    

提交回复
热议问题