5.2 Convert String to Date

20220108 The lubridate (Spinu, Grolemund, and Wickham 2021) package is the go to package for converting strings that represent a date into the date and time formats for computing with dates.

dt <- ymd("20220108")

Let’s have a look at the value:

## [1] "2022-01-08"

Often we will want to do this in wrangling a dataset:

ds <- read_csv("summary.csv", show_col_types=FALSE)

ds %>%
  mutate(date=ymd(date)) %>%


Spinu, Vitalie, Garrett Grolemund, and Hadley Wickham. 2021. Lubridate: Make Dealing with Dates a Little Easier. https://CRAN.R-project.org/package=lubridate.

Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2021 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0