Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

R – Problem Storing lubridate dates in a dataframe

When I’m trying to store date in a DF it is getting represented as a number instead of a data format. Here is my example.

library(lubridate)

df1 = data.frame(task = c('do somthing', 'do something else', 'do something more')
                 ,Start_date = c(NA, NA, NA))

Start_date = ymd("2023-12-01")
df1$Date_Start[1] = Start_date

Start_date     #this returns a "2023-12-01"
df1$Date_Start[1]  #this returns a 19692

I want df1$Date_Start[1] to store "2023-12-01"

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can specify directly your Date format:

library(lubridate)

df1 = data.frame(task = c('do somthing', 'do something else', 'do something more')
             ,Start_date = c(NA, NA, NA))

df1$Start_date[1] <- format(ymd("2023-12-01"), "%Y-%m-%d")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading