I have a dataset which looks like this:
df<-data.frame("Category"=c("A","B","C","D","A","B","C","D"),"Quarter"=c("2021 Q1","2021 Q1","2021 Q1","2021 Q1","2021 Q2","2021 Q2","2021 Q2","2021 Q2"),Variable1=c(1005,2007,1684,1545,4648,5016,4646,5555),Variable2=c(48,500,100,350,357,565,498,600))
What I'd like to do, using the data, would look like this:
I can't seem to find any similar questions asked here. I did see there are alternative approaches where I could use the pivot_longer function but this wouldn't give me the same table that I'm looking for.
Does anyone have any suggestions? Is this possible to do with R?


knitr::kableandkableExtrapackage. Specificallyadd_header_abovefunction.tidyr::pivot_wider(df, names_from = Quarter, values_from = starts_with('Variable'))