【问题标题】:How to spread using dcast?如何使用 dcast 进行传播?
【发布时间】:2015-03-19 06:20:40
【问题描述】:

我想用reshape2::dcast 来写下面的tidyr::spread 调用

stocks <- data.frame(
  time = as.Date('2009-01-01') + 0:9,
  X = rnorm(10, 0, 1),
  Y = rnorm(10, 0, 2),
  Z = rnorm(10, 0, 4)
)
stocksm <- stocks %>% gather(stock, price, -time)

stocksm %>% spread(time, price)

我无法确定要传递给 fun.aggregate 的内容

【问题讨论】:

    标签: r reshape2 tidyr


    【解决方案1】:

    您可以使用这种方法:

    library(reshape2)
    dcast(stocksm, stock ~ time)
    

    【讨论】:

      猜你喜欢
      • 2016-05-15
      • 2015-03-20
      • 2016-06-14
      • 2019-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-26
      相关资源
      最近更新 更多