0

I have the following part of my data:

    test <- wrapr::build_frame(
   "date_time"            , "automatic", "validate" |
     "2020-12-01 00:34:58", "sombra"   , "sombra"   |
     "2020-12-01 00:34:59", "organismo", "sombra"   |
     "2020-12-01 00:35:00", "partes"   , "sombra"   |
     "2020-12-01 00:35:01", "sombra"   , "sombra"   |
     "2020-12-01 00:36:02", "organismo", "sombra"   |
     "2020-12-01 00:36:03", "organismo", "partes"   |
     "2020-12-01 06:35:58", "sombra"   , "sombra"   |
     "2020-12-01 06:35:59", "partes"   , "sombra"   |
     "2020-12-01 06:36:00", "sombra"   , "sombra"   |
     "2020-12-01 06:36:01", "sombra"   , "partes"   |
     "2020-12-01 06:37:15", "organismo", "sombra"   |
     "2020-12-01 06:37:16", "partes"   , "sombra"   )

The column date_time corresponds to date (year, month and day) and time (hour, minute and second). This column has time values (not all here) for each second for every 3 minutes, after the third minute the data (next row) starts +-30 minutes later (again, not all data here).

I would create a column called cycle that gets the first date_time after this interval of +-30min and repeat this value until the next cycle of 3 minutes.

output desired for this data:

wrapr::build_frame(
   "date_time"            , "automatic", "validate", "cycle"               |
     "2020-12-01 00:34:58", "sombra"   , "sombra"  , "2020-12-01 00:34:58" |
     "2020-12-01 00:34:59", "organismo", "sombra"  , "2020-12-01 00:34:58" |
     "2020-12-01 00:35:00", "partes"   , "sombra"  , "2020-12-01 00:34:58" |
     "2020-12-01 00:35:01", "sombra"   , "sombra"  , "2020-12-01 00:34:58" |
     "2020-12-01 00:36:02", "organismo", "sombra"  , "2020-12-01 00:34:58" |
     "2020-12-01 00:36:03", "organismo", "partes"  , "2020-12-01 00:34:58" |
     "2020-12-01 06:35:58", "sombra"   , "sombra"  , "2020-12-01 06:35:58" |
     "2020-12-01 06:35:59", "partes"   , "sombra"  , "2020-12-01 06:35:58" |
     "2020-12-01 06:36:00", "sombra"   , "sombra"  , "2020-12-01 06:35:58" |
     "2020-12-01 06:36:01", "sombra"   , "partes"  , "2020-12-01 06:35:58" |
     "2020-12-01 06:37:15", "organismo", "sombra"  , "2020-12-01 06:35:58" |
     "2020-12-01 06:37:16", "partes"   , "sombra"  , "2020-12-01 06:35:58" )

Thanks all

Wilson Souza
  • 830
  • 4
  • 12
  • why does a new cycle start at `06:35:58`, one minute after the previous one? – Waldi Aug 04 '22 at 20:13
  • Because is the first time after an interval (> 30min after previous time) – Wilson Souza Aug 04 '22 at 20:21
  • 1
    [Create grouping variable for consecutive sequences](https://stackoverflow.com/questions/5222061/create-grouping-variable-for-consecutive-sequences-and-split-vector) and grab the first time by group. – Henrik Aug 05 '22 at 11:57

0 Answers0