Time difference between rows in R dplyr, different units

前端 未结 2 1411
野趣味
野趣味 2021-01-19 16:49

Here is my example. I am reading the following file: sample_data

library(dplyr)

txt <- c(\'\"\",  \"MDN\",                  \"Cl_Date\"\',
          \'\"         


        
2条回答
  •  太阳男子
    2021-01-19 17:36

    According to @hadley here, the solution is to use lubridate instead of relying on base R.

    This would be something like:

    ts %>% 
      group_by(MDN) %>% 
      arrange(Cl_Date) %>%
      mutate(as.duration(Cl_Date %--% lag(Cl_Date)))
    

提交回复
热议问题