What function I should use if I want to convert from data like this
Data like this
What function I should use if I want to convert from data like this
Data like this
Try reshaping and please next time include data using dput()
not screenshots:
library(dplyr)
library(tidyr)
#Data
df <- data.frame(Country=rep(c('Spain','Croatia'),5),
quarter=as.Date(c('2017-03-31','2017-03-31',
'2017-06-30','2017-06-30',
'2017-09-30','2017-09-30',
'2017-12-31','2017-12-31',
'2018-03-31','2018-03-31')),
employment_index=runif(10,98,107))
#Code
new <- df %>% pivot_wider(names_from = Country,values_from=employment_index)
Output:
# A tibble: 5 x 3
quarter Spain Croatia
<date> <dbl> <dbl>
1 2017-03-31 99.8 99.1
2 2017-06-30 103. 105.
3 2017-09-30 98.7 103.
4 2017-12-31 103. 104.
5 2018-03-31 100. 99.9