Reset variable value based on condition

You can perform time aggregation with tsible and dplyr packages.

If you need more specific help, please provide a proper REPRoducible EXample (reprex) illustrating your issue.