I need to create a detector usage table where the rows are individual detectors and the columns are the full date range over which they all were active. Within this table a 1 indicates the detector is active on a given day and a 0 indicates that a detector was inactive. The traps were activated in groups delineated by "site" (eg site: A1,B1,C1). The continuous date range in the columns needs to start the first day the first trap was active and end the last day the last trap was active.
Currently I have following data tables to work with
Site use table:
> site.use.df
site first last
1: A1 1/1/2018 1/10/2018
2: A1 1/21/2018 1/30/2018
3: B1 1/3/2018 1/12/2018
4: B1 1/16/2018 1/25/2018
5: C1 1/2/2018 1/11/2018
6: C1 1/13/2018 1/22/2018
Trap ID table:
> trapID.df
trapID site
1: 1 A1
2: 2 A1
3: 3 A1
4: 4 A1
5: 5 A1
6: 6 B1
7: 7 B1
8: 8 B1
9: 9 B1
10: 10 B1
11: 11 C1
12: 12 C1
13: 13 C1
14: 14 C1
15: 15 C1
Ideally, the full date range will be taken from the site use table and not entered by hand.
The end product I am looking for will look like this:
> detector.table
trapID site 1/1/2018 1/2/2018 1/3/2018 1/4/2018 1/5/2018 1/6/2018 1/7/2018 1/8/2018 1/9/2018
1: 1 A1 1 1 1 1 1 1 1 1 1
2: 2 A1 1 1 1 1 1 1 1 1 1
3: 3 A1 1 1 1 1 1 1 1 1 1
4: 4 A1 1 1 1 1 1 1 1 1 1
5: 5 A1 1 1 1 1 1 1 1 1 1
6: 6 B1 0 0 1 1 1 1 1 1 1
7: 7 B1 0 0 1 1 1 1 1 1 1
8: 8 B1 0 0 1 1 1 1 1 1 1
9: 9 B1 0 0 1 1 1 1 1 1 1
10: 10 B1 0 0 1 1 1 1 1 1 1
11: 11 C1 0 1 1 1 1 1 1 1 1
12: 12 C1 0 1 1 1 1 1 1 1 1
13: 13 C1 0 1 1 1 1 1 1 1 1
14: 14 C1 0 1 1 1 1 1 1 1 1
15: 15 C1 0 1 1 1 1 1 1 1 1
1/10/2018 1/11/2018 1/12/2018 1/13/2018 1/14/2018 1/15/2018 1/16/2018 1/17/2018 1/18/2018
1: 1 0 0 0 0 0 0 0 0
2: 1 0 0 0 0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