-1

I want the first dataset to change into the second. I tried attempting dcast() from reshape2 library but I'm not successful with it. How I may achieve such a dataframe transformation in R?

Given dataframe

date employee outcome
jan1 Alex 200
jan2 Alex 210
jan3 Alex 167
jan1 Tom 212
jan2 Tom 222
jan3 Tom 189
jan1 Kim 210
jan2 Kim 210
jan3 Kim 208

Desired dataframe

employee jan1 jan2 jan3
Alex 200 210 167
Tom 212 222 189
Kim 210 210 208
Phil
  • 7,287
  • 3
  • 36
  • 66
Mathica
  • 25
  • 1
  • 6

1 Answers1

1
library(tidyverse)
df %>%
  pivot_wider(names_from = date,
                      values_from = outcome)
deschen
  • 10,012
  • 3
  • 27
  • 50