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

Convert 20201223 to date format

How can I convert the format of column time in my data frame to date?

structure(list(geo = c("Alemanya", "Zona Euro", "Espanya", "Unió Europea", 
"França", "Itàlia"), time = c(20230201, 20230201, 20230201, 
20230201, 20230201, 20230201), values = c(0.5, 2, -0.9, 2.1, 
1.2, -2.3)), row.names = c(NA, -6L), class = c("tbl_df", "tbl", 
"data.frame"))

I would like to change it to aaaa-mm-dd.

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(tidyverse)


df |> 
  mutate(date = ymd(time))
#> # A tibble: 6 × 4
#>   geo              time values date      
#>   <chr>           <dbl>  <dbl> <date>    
#> 1 Alemanya     20230201    0.5 2023-02-01
#> 2 Zona Euro    20230201    2   2023-02-01
#> 3 Espanya      20230201   -0.9 2023-02-01
#> 4 Unió Europea 20230201    2.1 2023-02-01
#> 5 França       20230201    1.2 2023-02-01
#> 6 Itàlia       20230201   -2.3 2023-02-01

Created on 2023-04-13 with reprex v2.0.2

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