0

My dataset consists of individual animals located every couple days. I'd like to subset individuals who have 13 locations over no more than 20 days.

    TelemetryID       Date Easting Northing count
1          T001 2011-09-02  736412  3598549    26
2          T001 2011-09-02  736432  3598571    26
3          T001 2011-09-03  736432  3598571    26
4          T001 2011-09-04  736427  3598562    26
5          T001 2011-09-05  736436  3598563    26
6          T001 2011-09-06  736463  3598564    26
7          T001 2011-09-08  736442  3598568    26
8          T001 2011-09-10  736402  3598529    26
9          T001 2011-09-12  736448  3598544    26
10         T001 2011-09-13  736485  3598555    26
11         T001 2011-09-14  736437  3598575    26
12         T001 2011-09-15  736410  3598551    26
13         T001 2011-09-16  736440  3598565    26
14         T001 2011-09-17  736422  3598545    26
15         T001 2011-09-18  736436  3598565    26
16         T001 2011-09-20  736366  3598522    26
17         T001 2011-09-22  736422  3598568    26
18         T001 2011-09-23  736474  3598553    26
19         T001 2011-09-24  736429  3598537    26
20         T001 2011-09-25  736460  3598545    26
21         T001 2011-09-26  736421  3598526    26
22         T001 2011-09-28  736441  3598553    26
23         T001 2011-09-30  736462  3598557    26
24         T001 2011-10-03  736441  3598565    26
25         T001 2011-10-04  736439  3598576    26
26         T001 2011-10-05  736440  3598575    26
27         T002 2011-09-02  736532  3598498    10
28         T002 2011-09-02  736522  3598495    10
29         T002 2011-09-03  736524  3598485    10
30         T002 2011-09-04  736516  3598490    10
31         T002 2011-09-05  736537  3598489    10
32         T002 2011-09-06  736525  3598502    10
33         T002 2011-09-08  736520  3598483    10
34         T002 2011-09-10  736525  3598498    10
35         T002 2011-09-12  736527  3598487    10
36         T002 2011-09-12  736526  3598489    10
37         T003 2011-09-02  736442  3598616    40
38         T003 2011-09-02  736422  3598634    40
39         T003 2011-09-03  736453  3598644    40
40         T003 2011-09-04  736447  3598643    40
41         T003 2011-09-05  736460  3598648    40
42         T003 2011-09-06  736423  3598642    40
43         T003 2011-09-08  736448  3598657    40
44         T003 2011-09-10  736439  3598639    40
45         T003 2011-09-12  736483  3598676    40
46         T003 2011-09-13  736437  3598602    40
47         T003 2011-09-14  736424  3598611    40
48         T003 2011-09-15  736436  3598678    40
49         T003 2011-09-16  736473  3598651    40
50         T003 2011-09-17  736437  3598657    40
51         T003 2011-09-18  736443  3598633    40
52         T003 2011-09-20  736426  3598656    40
53         T003 2011-09-22  736442  3598665    40
54         T003 2011-09-23  736409  3598653    40
55         T003 2011-09-24  736435  3598633    40
56         T003 2011-09-25  736419  3598683    40
57         T003 2011-09-26  736425  3598625    40
58         T003 2011-09-28  736432  3598628    40
59         T003 2011-09-30  736458  3598605    40
60         T003 2011-10-03  736444  3598611    40

I have a bit of code to create the elapsed days column, but can't quite figure out how to then sort and extract the first thirteen fixes that occur within 20 days. Any help would be appreciated. Below is the mutate code for elapsed days.

WetSeasonElapsed<- df %>%
                    arrange (Date) %>%
                     group_by(TelemetryID) %>%
                      mutate( Elapsed = as.integer(Date - lag(Date))

The 13 points don't necessarily have to be the FIRST 13 points, just have to span no more than 20 days. Count refers to total number of locations/individual.

Output would look like below, retaining ID, locations, and dates, but reflecting the number of days elapsed and the count of points, which should be 13.

   TelemetryID       Date Easting Northing Elapsed count
1          T001 2011-09-02  736412  3598549   14    13
2          T001 2011-09-02  736432  3598571   14    13
3          T001 2011-09-03  736432  3598571   14    13
4          T001 2011-09-04  736427  3598562   14    13
5          T001 2011-09-05  736436  3598563   14    13
6          T001 2011-09-06  736463  3598564   14    13
7          T001 2011-09-08  736442  3598568   14    13
8          T001 2011-09-10  736402  3598529   14    13
9          T001 2011-09-12  736448  3598544   14    13
10         T001 2011-09-13  736485  3598555   14    13
11         T001 2011-09-14  736437  3598575   14    13
12         T001 2011-09-15  736410  3598551   14    13
13         T001 2011-09-16  736440  3598565   14    13
37         T003 2011-09-02  736442  3598616   15    13
38         T003 2011-09-02  736422  3598634   15    13
39         T003 2011-09-03  736453  3598644   15    13
40         T003 2011-09-04  736447  3598643   15    13
41         T003 2011-09-05  736460  3598648   15    13
42         T003 2011-09-06  736423  3598642   15    13
43         T003 2011-09-08  736448  3598657   15    13
44         T003 2011-09-10  736439  3598639   15    13
45         T003 2011-09-12  736483  3598676   15    13
46         T003 2011-09-13  736437  3598602   15    13
47         T003 2011-09-14  736424  3598611   15    13
48         T003 2011-09-15  736436  3598678   15    13
49         T003 2011-09-16  736473  3598651   15    13
  • 1
    Can you make your example reproducible? It will help others to provide you with an answer. https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – william3031 Jul 23 '20 at 01:25
  • 1
    Can you update expected output for the data shared? – Ronak Shah Jul 23 '20 at 01:48
  • I have eliminated excess data columns for reproducibility, and updated the expected output, thanks for the recommendations! – Craig Fischer Jul 23 '20 at 16:48

0 Answers0