0

I'd like to write the tidyr::spread call below in terms of 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)

I'm having trouble figuring out what to pass to fun.aggregate

4

1 回答 1

0

您可以使用这种方法:

library(reshape2)
dcast(stocksm, stock ~ time)
于 2015-01-20T21:17:01.613 回答