How to send output to specific location through pipes in R

后端 未结 1 1664
情话喂你
情话喂你 2021-01-27 02:19

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         


        
相关标签:
1条回答
  • 2021-01-27 02:39

    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"
    
    0 讨论(0)
提交回复
热议问题