This is the input
library(lubridate)
library(tidyverse)
library(stringr)
library(dplyr)
dataset <- data.frame(A = c("12345 Software Inc","12346 Software In","123463 Software In"),
B = c(12345,1234523,234234234),
C = c(ABC-1244, DEF-1134,ACF-1234),
X.Y DATE = c("1-May-2019","2-Jun-2020","3-July-2020"),
XX.YY DATE = c("1-May-2019","5-Jun-2020","4-July-2020"),
Check_DATE = c("1-May-2019","2-Jun-2020","3-July-2020")
)
date_parser <- function(column){
if(any(grepl("[-]",column))){
format(parse_date_time(column,orders = c("bdy","dmy","dby","ymd","mdy","ydm","%d-%m-%Y %H:%M:%S","%m-%d-%Y %H:%M:%S","%Y-%m-%d %H:%M:%S","%d-%m-%Y","%d-%b-%Y")),"%d-%m-%Y")
}
else column
}
date_format_change <- function(dataset1) {
data <- dataset1 %>%
mutate_at(-1,~ stringr::str_replace_all(.,"\\/","-")) %>%
purrr::map_dfr(~date_parser(.))
View(data)
}
date_format_change(dataset)
Output Received : [![enter image description here][2]][2]
[1]: https://i.stack
.
The Date has not changed. and
there columns have become NA. I want the output should not have any NA columns and date should be DD-MM-YYYY