As a part of a larger project, I am trying to define two POSIX dates and calculate the middle of the time period
I have tried the following code. The first calculation works as expected (with a binary ‘+’ for POSIX objects) resulting in
[1] “2024-06-01 23:59:30 AEST”
but the second calculation throws an error message
Error in +.POSIXt
(period_start, period_end) :
binary ‘+’ is not defined for “POSIXt” objects
Just can’t work our what I am missing here
Example code is
library(lubridate)
period_start <- as.POSIXct(“2024-05-29 00:00”, format = “%Y-%m-%d %H:%M”)
period_end <- as.POSIXct(“2024-06-05 23:59”, format = “%Y-%m-%d %H:%M”)
period_middle <- period_start + (period_end – period_start) / 2
print(period_middle)
period_middle <- (period_start + period_end) / 2
print(period_middle)
ms821 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.