-1

I was wondering about how you convert this df

Market Date N
First 11/21/21 2
Second 11/21/21 3
Third 11/21/21 4
First 11/22/21 9
Second 11/22/21 6
Third 11/22/21 7

to this

Date First Second Third
11/21/21 2 3 4
11/22/21 9 6 7

1 Answers1

0

With tidyverse, we can use pivot_wider to get the data into the wide format.

library(tidyverse)

df %>% 
  pivot_wider(names_from = "Market", values_from = "N")

Output

  Date     First Second Third
  <chr>    <int>  <int> <int>
1 11/21/21     2      3     4
2 11/22/21     9      6     7

Data

df <- structure(list(Market = c("First", "Second", "Third", "First", 
"Second", "Third"), Date = c("11/21/21", "11/21/21", "11/21/21", 
"11/22/21", "11/22/21", "11/22/21"), N = c(2L, 3L, 4L, 9L, 6L, 
7L)), class = "data.frame", row.names = c(NA, -6L))
AndrewGB
  • 16,126
  • 5
  • 18
  • 49