I’m trying to subtract 2 character vectors containing date time information in the following format:
train2 <- data.frame(
time2 = c(
"2011-09-01 23:44:52.533", "2011-09-05 12:25:37.42", "2011-08-24 12:56:58.91",
"2011-10-25 07:18:14.722", "2011-10-25 07:19:51.697"
),
time3 = c(
"2011-09-01 23:43:59.752", "2011-09-05 12:25:01.187",
"2011-08-24 12:55:13.012", "2011-10-25 07:16:51.759",
"2011-10-25 07:16:51.759"
)
)
I’ve hunted around and played with zoo, as.Date, as.POSIXct, etc. to try and find the correct code to subtract 2 datetime objects and get an answer in seconds but without luck.
I’d appreciate any suggestions.
Easy peasy:
And for your data:
and added back as a numeric to the data frame: