0

It should be easy, but I have not been able to wrap my brain how to accomplish my goal.

I would like to create an indicator that tallies changes in a status in a sequence.

have <- tibble::tribble(
  ~hurricane, ~ISO_TIME,
  0, "2020-11-01 12:00:00",
  0, "2020-11-01 15:00:00",
  1, "2020-11-01 18:00:00",
  1, "2020-11-01 21:00:00",
  1, "2020-11-02 00:00:00",
  0, "2020-11-02 01:30:00",
  0, "2020-11-02 03:00:00",
  0, "2020-11-02 06:00:00",
  1, "2020-11-02 09:00:00",
  1, "2020-11-02 12:00:00",
  0, "2020-11-02 15:00:00",
  0, "2020-11-02 18:00:00",
  1, "2020-11-02 21:00:00",
  1, "2020-11-03 00:00:00",
  1, "2020-11-03 03:00:00",
  0, "2020-11-03 06:00:00",
  1, "2020-11-03 09:00:00"
  )
want <- tibble::tribble(
  ~hurricane, ~ISO_TIME, ~event_change_tally,
  0, "2020-11-01 12:00:00", 0,
  0, "2020-11-01 15:00:00", 0,
  1, "2020-11-01 18:00:00", 1,
  1, "2020-11-01 21:00:00", 1,
  1, "2020-11-02 00:00:00", 1,
  0, "2020-11-02 01:30:00", 2,
  0, "2020-11-02 03:00:00", 2,
  0, "2020-11-02 06:00:00", 2,
  1, "2020-11-02 09:00:00", 3,
  1, "2020-11-02 12:00:00", 3,
  0, "2020-11-02 15:00:00", 4,
  0, "2020-11-02 18:00:00", 4,
  1, "2020-11-02 21:00:00", 5,
  1, "2020-11-03 00:00:00", 5,
  1, "2020-11-03 03:00:00", 5,
  0, "2020-11-03 06:00:00", 6,
  1, "2020-11-03 09:00:00", 7
)

Any suggestions would be much appreciated!

k6adams
  • 406
  • 1
  • 3
  • 12

0 Answers0