0

I have a financial dataset.

dat = data.frame(Fundemental = rep(c("EPS", "ROE"), 2), 
Dates = c("2019-01-01", "2019-01-01", "2019-02-02", "2019-02-02"), 
Value = rnorm(4))
##
   Fundemental      Dates      Value
 1         EPS 2019-01-01  2.0685114
 2         ROE 2019-01-01 -0.4700701
 3         EPS 2019-02-02  0.3254684
 4         ROE 2019-02-02 -0.6270476

Is there a quick way in dplyr to group the data frame by date so the data.frame has column names c(Dates, Value, ROE, EPS) and looks something like this.

         Dates       EPS Value   ROE Value
 1       2019-01-01  2.0685114   0.3254684    
 2       2019-02-02 -0.4700701   0.6270046

I wrote some code using the Map function, but I really feel like it's over kill! Thanks in advance.

Jordan Wrong
  • 1,205
  • 1
  • 12
  • 32
  • Use `tidyr::spread`, `dat %>% spread(Fundemental, Value)` or any of the options from the marked link. – Ronak Shah Jan 21 '19 at 03:32
  • I think it's worth emphasising that [the `tidyr::spread`](https://stackoverflow.com/a/25023569/3246758) solution is more current than the others (esp. for someone tagging `tidyverse`) :) – jimjamslam Jan 21 '19 at 04:03
  • thank you! the reshape solution was not very good with multivariables. spread worked great!! – Jordan Wrong Jan 21 '19 at 04:06

0 Answers0