I was trying to use
library(dplyr)
library(tidyr)
library(stringr)
# Dataframe has "Date" column and date in the format "dd/mm/yyyy" or "dd/m/yyyy"
df <- data.frame(Date = c("10/1/2001", "15/01/2010", "15/2/2010", "20/02/2010", "25/3/2010", "31/03/2010"))
# extract into three columns
df %>% extract(Date, c("Day", "Month", "Year"), "([^/]+), ([^/]+), ([^)]+)")
But above code is returning:
Day Month Year
1 <NA> <NA> <NA>
2 <NA> <NA> <NA>
3 <NA> <NA> <NA>
4 <NA> <NA> <NA>
5 <NA> <NA> <NA>
6 <NA> <NA> <NA>
How to correctly extract the dates in the result as expected:
Day Month Year
1 10 1 2010
2 15 1 2010
3 15 2 2010
4 20 2 2010
5 25 3 2010
6 31 3 2010