I have seal data that is grouped by columns: ID, dive number, and dive phase. I summarize this data over 20 second intervals from my original dataframe. When I do this, it creates duplicate 20 second time intervals if two different dive phase types overlap in a 20 second window. I'd like to sum the values of beats_20max in those duplicate rows then have their dive phase be combination of the two (ex: A, B would become AB). Hopefully this will make sense after looking at my data below.
seal_ID diveNum dive_phase datetime HR_mean HR_max beats20_mean beats20_max
<chr> <dbl> <chr> <dttm> <dbl> <dbl> <dbl> <int>
8 Baikal 19 D 2019-04-02 14:43:00 38.6 44.8 6.5 12
9 Baikal 19 D 2019-04-02 14:43:20 42.2 48 7.5 14
10 Baikal 19 D 2019-04-02 14:43:40 44.0 54.1 8 15
11 Baikal 19 D 2019-04-02 14:44:00 45.5 61.9 8 15
12 Baikal 19 D 2019-04-02 14:44:20 42.1 49.2 7.5 14
13 Baikal 19 D 2019-04-02 14:44:40 39.9 44.1 7 13
14 Baikal 19 D 2019-04-02 14:45:00 45.5 54.5 8 15
15 Baikal 19 D 2019-04-02 14:45:20 44.6 53.1 8 15
16 Baikal 19 D 2019-04-02 14:45:40 45.9 51.7 8 15
17 Baikal 19 B 2019-04-02 14:46:00 46.1 51.7 7.5 14
18 Baikal 19 D 2019-04-02 14:46:00 55.8 59.4 1.5 2
19 Baikal 19 B 2019-04-02 14:46:20 47.4 57.1 8 15
20 Baikal 19 B 2019-04-02 14:46:40 45.4 53.6 8 15
As you can see, lines 17 and 18 are duplicate times but different dive phases, I'd like to sum the beats20_max column and make their dive phase "DB". There are multiple instances of this throughout the dataframe, so if there's a way I can just aggregate or use dplyr to fix this that would be very helpful. I should mention that when I do this aggregation or summarization, I'll need to make sure I still group by seal_ID and diveNum because some seal's datetimes are the same. Thanks for any advice!
Ideal outcome:
seal_ID diveNum dive_phase datetime beats20_max
<chr> <dbl> <chr> <dttm> <int>
8 Baikal 19 D 2019-04-02 14:43:00 12
9 Baikal 19 D 2019-04-02 14:43:20 14
10 Baikal 19 D 2019-04-02 14:43:40 15
11 Baikal 19 D 2019-04-02 14:44:00 15
12 Baikal 19 D 2019-04-02 14:44:20 14
13 Baikal 19 D 2019-04-02 14:44:40 13
14 Baikal 19 D 2019-04-02 14:45:00 15
15 Baikal 19 D 2019-04-02 14:45:20 15
16 Baikal 19 D 2019-04-02 14:45:40 15
17 Baikal 19 DB 2019-04-02 14:46:00 16
18 Baikal 19 B 2019-04-02 14:46:20 15
19 Baikal 19 B 2019-04-02 14:46:40 15