Different character types of same column into date format

I have an excel file with columns Date_of_visit & As_of_date and 2 rows. While I'm loading into data frame one row is in date format and another in numeric. I want to format the column into same format.

I'm trying the below code with no luck

    df$Date_of_visit <- as.Date(as.numeric(df$Date_of_visit), origin = "1899-12-30")
    df$As_of_date <- as.Date(as.numeric(df$As_of_date), origin = "1899-12-30")

Output :

I'm struggling with this from 2 days. Please help me out.

Many thanks,
Mouni

Hi,

Could you please create a reprex to provide us with some of the data you are working with and what you are trying to do to it. A reprex consists of the minimal code and data needed to recreate the issue/question you're having. You can find instructions how to build and share one here:

My first idea would be to use the date formatting function on the strings like this

myData = data.frame(date = c("16/01/2020", "01/05/2020"))
myData$date = as.Date(myData$date, format = "%d/%m/%Y")

class(myData$date)
#> [1] "Date"
myData$date
#> [1] "2020-01-16" "2020-05-01"

Created on 2020-09-29 by the reprex package (v0.3.0)

PJ

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.