Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to mutate a year quarter str into date?

I have a df that comes from an api with a Trimestre (Código) column in string format:

pib$`Trimestre (Código)` <- c(199101,199102,199103,199104,199201,199202,...)

but i need to mutate this column into date format. I have tried the folowing:

> 
> pib %>% 
> mutate(date = parse_date(`Trimestre (Código)`, format='%Y%q')) %>%
> select('Trimestre (Código)', "Setores e subsetores", Valor) %>%
> pivot_wider(names_from = "Setores e subsetores",
> values_from = Valor)

but I just receive the error ‘unsupported format %q’. How to do it?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

library(lubridate)
library(dplyr)

pib <- data.frame(Trimestre = c(199101,199102,199103,199104,199201,199202))

pib %>%
  mutate(date = yq(Trimestre))

Edit: Just saw you got the answer in the comments

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading