'How can I split this date?

I am working with this dataset and I am trying to separate the 'Date' column into the day, month, and year but have run into a problem doing it because it has the month as a character value. Any help would be great. Here's an image: Dataset



Solution 1:[1]

You can convert your Date column using as.Date(), specifying the format for the date; in this case, one option is "%d%B%y"

library(lubridate)
dataset = data.frame(Date=c("19MAY19","31MAY19"))
dataset %>% mutate(Date = as.Date(Date,"%d%B%y"),
                   y = year(Date),m=month(Date),d = day(Date))

Output:

        Date    y m  d
1 2019-05-19 2019 5 19
2 2019-05-31 2019 5 31

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 langtang