I am trying to import my excel data sheet and the date column is imported as a character column with some integer date values mixed in.
Now the class of date column is character.
I am trying to adjust the date column using
Agri$Date <- as.Date(Agri$Date, format="%d/%m/%Y")
The result is the cells with numbers have NAs and the cells with the dates was adjusted right
The function convert_to_date()
from the janitor package handles mixed date types like that.
For example, with your data:
Agri <- data.frame(Date = c("42864", "14/9/2017"))
Agri$Date <- janitor::convert_to_date(Agri$Date, character_fun = lubridate::dmy)
Agri
#> Date
#> 1 2017-05-09
#> 2 2017-09-14
library(lubridate)
Agri$Date_new<- dmy(Agri$Date)
Try by using above library.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With