Create an index that increases after each gap in otherwise regularily-increasing row

前端 未结 1 414
半阙折子戏
半阙折子戏 2021-01-27 00:28

I\'ve got a samples data frame which contains some readings at regularily-spaced timestamps (1 sec. interval).

                      TS           Pr         


        
相关标签:
1条回答
  • 2021-01-27 01:27
     samples$eventID <- cumsum(c(TRUE,diff(as.POSIXct(samples$TS))>1))
     samples
     #                      TS Pressure Temperature eventID
     #8  2014-08-26 00:18:26.8    105.0          30       1
     #9  2014-08-26 00:18:27.8    108.0          32       1
     #10 2014-08-26 00:18:28.8    109.9          31       1
     #11 2014-08-26 00:34:20.8    109.0          20       2
     #12 2014-08-26 00:34:21.8    100.0          24       2
     #13 2014-08-26 00:34:22.8     95.0          22       2
    
    0 讨论(0)
提交回复
热议问题