如何使用dcast进行传播?

时间:2015-01-20 21:12:25

标签: r reshape2 tidyr

我想根据tidyr::spread

撰写下面的reshape2::dcast来电
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

的内容

1 个答案:

答案 0 :(得分:0)

您可以使用此方法:

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