user3655531
user3655531

Reputation: 145

Add hour if missing in timestamp using lubridate

I have a list of timestamps in the factor format the I want to convert using lurbridate.

However some of the timestamps lack time 00:00:00:

2013-12-24 23:00:00
2013-12-24
2013-12-24 01:00:00

How do I expand the df$timestamp <- ymd_hms(df$Timestamp_factor) to insert 00:00:00 if time i missing?

Upvotes: 0

Views: 431

Answers (1)

Derek Corcoran
Derek Corcoran

Reputation: 4102

You can use the truncated term for lubridate to get those missing parameters. In this case, you are missing three parameters hour, minute and second

ymd_hms(c("2013-12-24 23:00:00", "2013-12-24", "2013-12-24 01:00:00"), truncated = 3)

That, however, will always return 00:00:00 as the time

Upvotes: 4

Related Questions