0

What function I should use if I want to convert from data like this

enter image description here

Data like this

enter image description here

ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81
Gina
  • 3
  • 3
  • 1
    Does this answer your question? [How to reshape data from long to wide format](https://stackoverflow.com/a/57013551/) – Ian Campbell Dec 08 '20 at 14:17

1 Answers1

0

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
Duck
  • 39,058
  • 13
  • 42
  • 84