This is a small sample from the df I am working with:
animal time period zone
<chr> <dbl> <chr> <chr>
1 HR1 0 q1 social
2 HR1 2.04 q1 social
3 HR1 2.1 q1 social
4 HR1 2.20 q1 interzone
5 HR1 2.44 q1 nest
6 HR1 2.47 q1 nest
7 HR1 2.68 q1 nest
8 HR1 2.71 q1 nest
9 HR1 2.87 q1 nest
10 HR1 3.20 q1 nest
I am trying to find a way to calculate how much time an animal spent in each zone. I would effectively like to generate another column where I get cumulative time for each of the visits to the zone. It would include taking max and minimum time point in the zone, subtracting them, and placing the end result into a new column. The end result should look something like this:
animal time period zone cum_time_zone
<chr> <dbl> <chr> <chr> <dbl>
1 HR1 0 q1 social NA
2 HR1 2.04 q1 social NA
3 HR1 2.1 q1 social 2.2
4 HR1 2.20 q1 interzone 0.24
5 HR1 2.44 q1 nest NA
6 HR1 2.47 q1 nest NA
7 HR1 2.68 q1 nest NA
8 HR1 2.71 q1 nest NA
9 HR1 2.87 q1 nest NA
10 HR1 3.20 q1 nest 0.76
I will be very grateful for any input!