I am writing a small code where i compare two times and find the difference and display it in HH:MM:SS format.
library(magrittr)
library(lubridate)
s1 <- ymd
When you use pipes the object on the left is the first input to the function by default. To stop that use curly braces ({}
).
library(lubridate)
difftime(s2, s1, units = "secs") %>%
as.numeric() %>%
seconds_to_period() %>%
{sprintf('%02d:%02d:%02d', hour(.), minute(.), second(.))}
#[1] "00:03:20"