Saturday, December 14, 2013

R - Lubridate - Reading Date/Time Data

I'm reading in date and time data from my sleep project using the parse_date_time() function from the lubridate package.

sleep$StartDateTime <- parse_date_time(paste(sleep$Date, sleep$StartTime), "%m-%d-%Y %H.%M", truncate = 2)

The date and time data were in two separate columns so I needed to use the paste()function. The minutes data is in the format HH.MM.

Also, I was getting NA data at first when the minutes data was 00 (at the top of the hour). I added the truncate argument so that it would ignore incomplete data in seconds and minutes.

Here is a good summary of the parse_date_time() function: http://www.inside-r.org/packages/cran/lubridate/docs/parse_date_time

No comments:

Post a Comment