Jack Jack - 9 months ago 22
R Question

taking time difference from time in different format in R

I have a data.table dt which have many records .

It have two columns datetime1, with value as "2017-04-19 09:54:00" of class


another column have time values like "7.97" of class
. It is for the same date.

I want to calculate a difference in the time in minutes. how can I do it in R

d.b d.b
Answer Source

You can use functions of lubridate to extract hour, minute, and second of the POSIXct and then calculate the difference.

x = as.POSIXct("2017-04-19 09:54:00", tz = "UTC")
hour(x) * 60 + minute(x) + second(x)/60 - 7.97 * 60
#[1] 115.8
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download