I have quite a big and messy dataset, where all the dates have different formats:
either 01.03.2022 or 03/01/2022
I would like to transform them to the same format.
So far I managed to change all "/" into a ".", but now the month and the day are in the wrong order.
Does anyone know how to switch strings seperated by the first slash, but not by the first point?
Furthermore it need to applied to the whole dataframe, because all date variables have the same problem.
Thank you so much.
## create a tibble
data <- tibble(
name = c("Josh", "Jasi", "Sophie", "Leni"),
date = c("1/17/1990", "24.09.1865", "3/13/2000", "14.04.2000")
)
## change / to a . in the date
data <- data.frame(lapply(data, function(x) {
gsub("/", ".", x)
}))
## print new data
print(data)