Jack - 1 month ago 7

R Question

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

`POSIXct`

another column have time values like "7.97" of class

`numeric`

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

Answer Source

You can use functions of `lubridate`

to extract `hour`

, `minute`

, and `second`

of the `POSIXct`

and then calculate the difference.

```
library(lubridate)
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
```