Is there a way to convert 20180801 to proper date ?

I have a column that is 20180801, 20180802, 20180803 and so on. I need to convert this column into proper y-mm-dd format. Is there a lubridate function to perform this ?

Also, I'm unaware if we have some direct functions to convert this numeric column into various columns such as year, month, date.

Much appreciated for your help.

Hi there TimeTravellerK,
you can use lubridate's date/time parsing functions to solve the problem:

Numeric_Dates_to_Convert <- c(20180801, 20180802, 20180803)
String_Dates_to_Convert <- c("20180801", "20180802", "20180803")
ymd(Numeric_Dates_to_Convert); ymd(String_Dates_to_Convert)
# [1] "2018-08-01" "2018-08-02" "2018-08-03"

See Lubridates CheatSheet for some helpers
On the first page of the cheetsheet, look for 'Get and Set Components' for converting Year, Month, Day functions. You may need to combine this with some tidyr/plyr/dplyr functions to create new columns for each of the components

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.