0

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?

4
  • How do you want to impute the month and day-of-month from the quarter?
    – Limey
    Commented Jul 4 at 15:28
  • @Limey, something like '01/01/1991' Commented Jul 4 at 15:30
  • 4
    Maybe: lubridate::yq(your_date_vector) will do?
    – Peter
    Commented Jul 4 at 15:33
  • yes, it did it. Commented Jul 4 at 15:37

1 Answer 1

-1
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

Not the answer you're looking for? Browse other questions tagged or ask your own question.