1

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

EthanMcQ
  • 31
  • 4

1 Answers1

2

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
langtang
  • 22,248
  • 1
  • 12
  • 27