-
Notifications
You must be signed in to change notification settings - Fork 0
/
Salfeedscript.R
1779 lines (1521 loc) · 194 KB
/
Salfeedscript.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
##Locations functions edited for Salmon feeding times and day/night times
##For each fish, (see if can do for each dayfile over multiple days)
library(xlsx) #make sure it's attached or won't create output file
#salfeedon12 <- subset(dayfile, SMEAL12 == 'Y')
#salfeedon14 <- subset(dayfile, SMEAL14 == 'Y')
#salfeedon15 <- subset(dayfile, SMEAL15 == 'Y')
#salfeedoff12 <- subset(dayfile, SMEAL12 == 'N')
#salfeedoff14 <- subset(dayfile, SMEAL14 == 'N')
#salfeedoff15 <- subset(dayfile, SMEAL15 == 'N')
#(can do hexplots too, but locations more important)
##Repeat for Day/Night
#########This script uses & SMEAL_ == 'Y' or 'N' in function; instead of first subsetting dayfile by SMEAL.
# LOAD FILES-------------------------------------------------------------------------------------------------------------------
workingdir = "H:/Data processing/2018 Lumpfish Husbandry/6b. Coded Fish CSV/T1 2wks coded fish" ## Reload after doing hides workingdir
setwd(workingdir)
masterfileloc = "H:/Data processing/AcousticTagFile_2018v6.xlsx" # change to location of AcousticTagFile.xlsx
#Lumpfish Laga 2018 Coded Dayfile classes
dayfile.classes = c('NULL', 'numeric', 'factor', 'factor', 'POSIXct', 'double', 'double',
'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'factor',
'factor', 'factor', 'factor', 'factor', 'double', 'double', 'double',
'double', 'double', 'double', 'double', 'double', 'double', 'double',
'double', 'double', 'double', 'double', 'double', 'double', 'double',
'double', 'double', 'double', 'double', 'factor', 'factor', 'factor',
'factor', 'factor', 'factor', 'factor', 'factor', 'factor', 'factor',
'factor', 'factor', 'factor', 'double', 'double', 'double', 'double',
'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double'
)
#LOAD LOCATIONS CODING DATA ##Need library(xlsx), make sure not detached
locations.lookup <- read.xlsx(masterfileloc, sheetIndex = 11, startRow = 1, endRow = 61, colIndex = seq(1, 7)) # read in codes from Locations Coding spreadsheet
#locations.lookup <- readWorksheetFromFile(masterfileloc, sheet = 12, startRow = 1, endCol = 7) # read in codes from Locations Coding spreadsheet
rownames(locations.lookup) <- locations.lookup$Code
#----- 1. FUNCTION TO CALCULATE SUMMARY OF FISH LOCATIONS (Pen total) for Sal Feed on (for One loaded dayfile)----
locationssalfeedon <- function()
{
# pen 12 location summary
dayfile.bot <- subset(dayfile, SMEAL12 == 'Y' & BOT == 'B' & PEN == '12' & SEC >= 0)
dayfile.top <- subset(dayfile, SMEAL12 == 'Y' & BOT == 'Z' & PEN == '12' & SEC >= 0)
dayfile.out <- subset(dayfile, SMEAL12 == 'Y' & OUT == '12OE' & PEN == '12' & SEC >= 0 | SMEAL12 == 'Y' & OUT == '12OS' & PEN == '12' & SEC >= 0 | SMEAL12 == 'Y' & OUT == '12ON' & PEN == '12' & SEC >= 0 | SMEAL12 == 'Y' & OUT == '12OW' & PEN == '12' & SEC >= 0)
dayfile.edg <- subset(dayfile, SMEAL12 == 'Y' & EDG == '12EN' & PEN == '12' & SEC >= 0 | SMEAL12 == 'Y' & EDG == '12EW' & PEN == '12' & SEC >= 0 | SMEAL12 == 'Y' & EDG == '12ES' & PEN == '12' & SEC >= 0 | SMEAL12 == 'Y' & EDG == '12EE' & PEN == '12' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SMEAL12 == 'Y' & BIGC == '12CNW' & PEN == '12' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SMEAL12 == 'Y' & BIGC == '12CNE' & PEN == '12' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SMEAL12 == 'Y' & BIGC == '12CSW' & PEN == '12' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SMEAL12 == 'Y' & BIGC == '12CSE' & PEN == '12' & SEC >= 0)
dayfile.cen <- subset(dayfile, SMEAL12 == 'Y' & CEN == '12MH' & PEN == '12' & SEC >= 0 | SMEAL12 == 'Y' & CEN == '12MM' & PEN == '12' & SEC >= 0 | SMEAL12 == 'Y' & CEN == '12ML' & PEN == '12' & SEC >= 0)
dayfile.hid <- subset(dayfile, SMEAL12 == 'Y' & HID == 'P12HE' & PEN == '12' & SEC >= 0 | SMEAL12 == 'Y' & HID == 'P12HW' & PEN == '12' & SEC >= 0)
dayfile.fs <- subset(dayfile, SMEAL12 == 'Y' & FS == 'FS12' & PEN == '12' & SEC >= 0)
#location.sum <- data.frame(c(nrow(dayfile.bot), nrow(dayfile.top), nrow(dayfile.out), nrow(dayfile.edg), nrow(dayfile.bigc), nrow(dayfile.cen), nrow(dayfile.hid)))
location.sum <- data.frame(c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC), sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600))
rownames(location.sum) <- c('<15m', '>15m', 'outer', 'edge', 'NW_corner', 'NE_corner', 'SW_corner', 'SE_corner', 'centre', 'hides', 'feed station')
colnames(location.sum) <- 'Pen12'
# pen 14 location summary
dayfile.bot <- subset(dayfile, SMEAL14 == 'Y' & BOT == 'B' & SEC >= 0 & PEN == '14' & SEC >= 0)
dayfile.top <- subset(dayfile, SMEAL14 == 'Y' & BOT == 'Z' & PEN == '14' & SEC >= 0)
dayfile.out <- subset(dayfile, SMEAL14 == 'Y' & OUT == '14OE' & PEN == '14' & SEC >= 0| SMEAL14 == 'Y' & OUT == '14OS' & PEN == '14' & SEC >= 0 | SMEAL14 == 'Y' & OUT == '14ON' & PEN == '14' & SEC >= 0 | SMEAL14 == 'Y' & OUT == '14OW' & PEN == '14' & SEC >= 0)
dayfile.edg <- subset(dayfile, SMEAL14 == 'Y' & EDG == '14EN' & PEN == '14' & SEC >= 0 | SMEAL14 == 'Y' & EDG == '14EW' & PEN == '14' & SEC >= 0 | SMEAL14 == 'Y' & EDG == '14ES' & PEN == '14' & SEC >= 0 | SMEAL14 == 'Y' & EDG == '14EE' & PEN == '14' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SMEAL14 == 'Y' & BIGC == '14CNW' & PEN == '14' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SMEAL14 == 'Y' & BIGC == '14CNE' & PEN == '14' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SMEAL14 == 'Y' & BIGC == '14CSW' & PEN == '14' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SMEAL14 == 'Y' & BIGC == '14CSE' & PEN == '14' & SEC >= 0)
dayfile.cen <- subset(dayfile, SMEAL14 == 'Y' & CEN == '14MH' & PEN == '14' & SEC >= 0 | SMEAL14 == 'Y' & CEN == '14MM' & PEN == '14' & SEC >= 0 | SMEAL14 == 'Y' & CEN == '14ML' & PEN == '14' & SEC >= 0)
dayfile.hid <- subset(dayfile, SMEAL14 == 'Y' & HID == 'P14HW' & PEN == '14' & SEC >= 0 | SMEAL14 == 'Y' & HID == 'P14HE' & PEN == '14' & SEC >= 0)
dayfile.fs <- subset(dayfile, SMEAL14 == 'Y' & FS == 'FS14' & PEN == '14' & SEC >= 0)
#location.sum$Pen14 <- c(nrow(dayfile.bot), nrow(dayfile.top), nrow(dayfile.out), nrow(dayfile.edg), nrow(dayfile.bigc), nrow(dayfile.cen), nrow(dayfile.hid))
location.sum$Pen14 <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600))
# pen 15 location summary
dayfile.bot <- subset(dayfile, SMEAL15 == 'Y' & BOT == 'B' & SEC >= 0 & PEN == '15' & SEC >= 0)
dayfile.top <- subset(dayfile, SMEAL15 == 'Y' & BOT == 'Z' & PEN == '15' & SEC >= 0)
dayfile.out <- subset(dayfile, SMEAL15 == 'Y' & OUT == '15OE' & PEN == '15' & SEC >= 0| SMEAL15 == 'Y' & OUT == '15OS' & PEN == '15' & SEC >= 0 | SMEAL15 == 'Y' & OUT == '15ON' & PEN == '15' & SEC >= 0 | SMEAL15 == 'Y' & OUT == '15OW' & PEN == '15' & SEC >= 0)
dayfile.edg <- subset(dayfile, SMEAL15 == 'Y' & EDG == '15EN' & PEN == '15' & SEC >= 0 | SMEAL15 == 'Y' & EDG == '15EW' & PEN == '15' & SEC >= 0 | SMEAL15 == 'Y' & EDG == '15ES' & PEN == '15' & SEC >= 0 | SMEAL15 == 'Y' & EDG == '15EE' & PEN == '15' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SMEAL15 == 'Y' & BIGC == '15CNW' & PEN == '15' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SMEAL15 == 'Y' & BIGC == '15CNE' & PEN == '15' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SMEAL15 == 'Y' & BIGC == '15CSW' & PEN == '15' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SMEAL15 == 'Y' & BIGC == '15CSE' & PEN == '15' & SEC >= 0)
dayfile.cen <- subset(dayfile, SMEAL15 == 'Y' & CEN == '15MH' & PEN == '15' & SEC >= 0 | SMEAL15 == 'Y' & CEN == '15MM' & PEN == '15' & SEC >= 0 | SMEAL15 == 'Y' & CEN == '15ML' & PEN == '15' & SEC >= 0)
dayfile.hid <- subset(dayfile, SMEAL15 == 'Y' & HID == 'P15HW' & PEN == '15' & SEC >= 0 | SMEAL15 == 'Y' & HID == 'P15HE' & PEN == '15' & SEC >= 0)
dayfile.fs <- subset(dayfile, SMEAL15 == 'Y' & FS == 'FS15' & PEN == '15' & SEC >= 0)
#location.sum$Pen15 <- c(nrow(dayfile.bot), nrow(dayfile.top), nrow(dayfile.out), nrow(dayfile.edg), nrow(dayfile.bigc), nrow(dayfile.cen), nrow(dayfile.hid))
location.sum$Pen15 <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
location.sum
}
#--- 2. Batch location summary for multiple day files (files in same folder) SMEALON------
batch.locationssalfeedon <- function()
{
files <- list.files(path = workingdir, pattern = '*.csv', all.files = FALSE, recursive = FALSE)
locations.P12 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P12) <- 'ID'
rownames(locations.P12) <- c('P12_<15m', 'P12_>15m', 'P12_outer', 'P12_edge', 'P12_NWcorner', 'P12_NEcorner', 'P12_SWcorner', 'P12_SEcorner', 'P12_centre', 'P12_hides', 'P12_feedstation')
locations.P14 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P14) <- 'ID'
rownames(locations.P14) <- c('P14_<15m', 'P14_>15m', 'P14_outer', 'P14_edge', 'P14_NWcorner', 'P14_NEcorner', 'P14_SWcorner', 'P14_SEcorner', 'P14_centre', 'P14_hides', 'P14_feedstation')
locations.P15 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P15) <- 'ID'
rownames(locations.P15) <- c('P15_<15m', 'P15_>15m', 'P15_outer', 'P15_edge', 'P15_NWcorner', 'P15_NEcorner', 'P15_SWcorner', 'P15_SEcorner', 'P15_centre', 'P15_hides', 'P15_feedstation')
for (i in 1:length(files))
{
dayfile.loc <- files[[i]]
dayfile <- read.csv(dayfile.loc, header = TRUE, sep = ",", colClasses = dayfile.classes)
#SORT BY TIME AND TAG
dayfile <- dayfile[order(dayfile$EchoTime, na.last = FALSE, decreasing = FALSE, method = c("shell")),] # sort by time
dayfile <- dayfile[order(dayfile$Period, na.last = FALSE, decreasing = FALSE, method = c("shell")),] # sort by tag
# pen 12 location summary
dayfile.bot <- subset(dayfile, SMEAL12 == 'Y' & BOT == 'B' & PEN == '12' & SEC >= 0)
dayfile.top <- subset(dayfile, SMEAL12 == 'Y' & BOT == 'Z' & PEN == '12' & SEC >= 0)
dayfile.out <- subset(dayfile, SMEAL12 == 'Y' & OUT == '12OE' & PEN == '12' & SEC >= 0 | SMEAL12 == 'Y' & OUT == '12OS' & PEN == '12' & SEC >= 0 | SMEAL12 == 'Y' & OUT == '12ON' & PEN == '12' & SEC >= 0 | SMEAL12 == 'Y' & OUT == '12OW' & PEN == '12' & SEC >= 0)
dayfile.edg <- subset(dayfile, SMEAL12 == 'Y' & EDG == '12EN' & PEN == '12' & SEC >= 0 | SMEAL12 == 'Y' & EDG == '12EW' & PEN == '12' & SEC >= 0 | SMEAL12 == 'Y' & EDG == '12ES' & PEN == '12' & SEC >= 0 | SMEAL12 == 'Y' & EDG == '12EE' & PEN == '12' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SMEAL12 == 'Y' & BIGC == '12CNW' & PEN == '12' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SMEAL12 == 'Y' & BIGC == '12CNE' & PEN == '12' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SMEAL12 == 'Y' & BIGC == '12CSW' & PEN == '12' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SMEAL12 == 'Y' & BIGC == '12CSE' & PEN == '12' & SEC >= 0)
dayfile.cen <- subset(dayfile, SMEAL12 == 'Y' & CEN == '12MH' & PEN == '12' & SEC >= 0 | SMEAL12 == 'Y' & CEN == '12MM' & PEN == '12' & SEC >= 0 | SMEAL12 == 'Y' & CEN == '12ML' & PEN == '12' & SEC >= 0)
dayfile.hid <- subset(dayfile, SMEAL12 == 'Y' & HID == 'P12HW' & PEN == '12' & SEC >= 0 | SMEAL12 == 'Y' & HID == 'P12HE' & PEN == '12' & SEC >= 0)
dayfile.fs <- subset(dayfile, SMEAL12 == 'Y' & FS == 'FS12' & PEN == '12' & SEC >= 0)
locations.P12[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
# pen 14 location summary
dayfile.bot <- subset(dayfile, SMEAL14 == 'Y' & BOT == 'B' & SEC >= 0 & PEN == '14' & SEC >= 0)
dayfile.top <- subset(dayfile, SMEAL14 == 'Y' & BOT == 'Z' & PEN == '14' & SEC >= 0)
dayfile.out <- subset(dayfile, SMEAL14 == 'Y' & OUT == '14OE' & PEN == '14' & SEC >= 0| SMEAL14 == 'Y' & OUT == '14OS' & PEN == '14' & SEC >= 0 | SMEAL14 == 'Y' & OUT == '14ON' & PEN == '14' & SEC >= 0 | SMEAL14 == 'Y' & OUT == '14OW' & PEN == '14' & SEC >= 0)
dayfile.edg <- subset(dayfile, SMEAL14 == 'Y' & EDG == '14EN' & PEN == '14' & SEC >= 0 | SMEAL14 == 'Y' & EDG == '14EW' & PEN == '14' & SEC >= 0 | SMEAL14 == 'Y' & EDG == '14ES' & PEN == '14' & SEC >= 0 | SMEAL14 == 'Y' & EDG == '14EE' & PEN == '14' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SMEAL14 == 'Y' & BIGC == '14CNW' & PEN == '14' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SMEAL14 == 'Y' & BIGC == '14CNE' & PEN == '14' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SMEAL14 == 'Y' & BIGC == '14CSW' & PEN == '14' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SMEAL14 == 'Y' & BIGC == '14CSE' & PEN == '14' & SEC >= 0)
dayfile.cen <- subset(dayfile, SMEAL14 == 'Y' & CEN == '14MH' & PEN == '14' & SEC >= 0 | SMEAL14 == 'Y' & CEN == '14MM' & PEN == '14' & SEC >= 0 | SMEAL14 == 'Y' & CEN == '14ML' & PEN == '14' & SEC >= 0)
dayfile.hid <- subset(dayfile, SMEAL14 == 'Y' & HID == 'P14HW' & PEN == '14' & SEC >= 0 | SMEAL14 == 'Y' & HID == 'P14HE' & PEN == '14' & SEC >= 0)
dayfile.fs <- subset(dayfile, SMEAL14 == 'Y' & FS == 'FS14' & PEN == '14' & SEC >= 0)
locations.P14[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
# pen 15 location summary
dayfile.bot <- subset(dayfile, SMEAL15 == 'Y' & BOT == 'B' & SEC >= 0 & PEN == '15' & SEC >= 0)
dayfile.top <- subset(dayfile, SMEAL15 == 'Y' & BOT == 'Z' & PEN == '15' & SEC >= 0)
dayfile.out <- subset(dayfile, SMEAL15 == 'Y' & OUT == '15OE' & PEN == '15' & SEC >= 0| SMEAL15 == 'Y' & OUT == '15OS' & PEN == '15' & SEC >= 0 | SMEAL15 == 'Y' & OUT == '15ON' & PEN == '15' & SEC >= 0 | SMEAL15 == 'Y' & OUT == '15OW' & PEN == '15' & SEC >= 0)
dayfile.edg <- subset(dayfile, SMEAL15 == 'Y' & EDG == '15EN' & PEN == '15' & SEC >= 0 | SMEAL15 == 'Y' & EDG == '15EW' & PEN == '15' & SEC >= 0 | SMEAL15 == 'Y' & EDG == '15ES' & PEN == '15' & SEC >= 0 | SMEAL15 == 'Y' & EDG == '15EE' & PEN == '15' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SMEAL15 == 'Y' & BIGC == '15CNW' & PEN == '15' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SMEAL15 == 'Y' & BIGC == '15CNE' & PEN == '15' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SMEAL15 == 'Y' & BIGC == '15CSW' & PEN == '15' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SMEAL15 == 'Y' & BIGC == '15CSE' & PEN == '15' & SEC >= 0)
dayfile.cen <- subset(dayfile, SMEAL15 == 'Y' & CEN == '15MH' & PEN == '15' & SEC >= 0 | SMEAL15 == 'Y' & CEN == '15MM' & PEN == '15' & SEC >= 0 | SMEAL15 == 'Y' & CEN == '15ML' & PEN == '15' & SEC >= 0)
dayfile.hid <- subset(dayfile, SMEAL15 == 'Y' & HID == 'P15HW' & PEN == '15' & SEC >= 0 | SMEAL15 == 'Y' & HID == 'P15HE' & PEN == '15' & SEC >= 0)
dayfile.fs <- subset(dayfile, SMEAL15 == 'Y' & FS == 'FS15' & PEN == '15' & SEC >= 0)
locations.P15[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
}
location.sum <- rbind(locations.P12, locations.P14, locations.P15)
location.sum$ID <- NULL
location.sum
#loadWorkbook('LocationsOutput.xlsx', create = TRUE)
#writeWorksheetToFile('LocationsOutput.xlsx', location.sum, 'Sheet 1')
write.xlsx(location.sum, 'LocationsOutputSMEALon.xlsx')
}
#----- 1b. FUNCTION TO CALCULATE SUMMARY OF (Pen total) FISH LOCATIONS for Sal Feed OFF (One loaded dayfile)-----
locationssalfeedoff <- function()
{
# pen 12 location summary
dayfile.bot <- subset(dayfile, SMEAL12 == 'N' & BOT == 'B' & PEN == '12' & SEC >= 0)
dayfile.top <- subset(dayfile, SMEAL12 == 'N' & BOT == 'Z' & PEN == '12' & SEC >= 0)
dayfile.out <- subset(dayfile, SMEAL12 == 'N' & OUT == '12OE' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & OUT == '12OS' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & OUT == '12ON' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & OUT == '12OW' & PEN == '12' & SEC >= 0)
dayfile.edg <- subset(dayfile, SMEAL12 == 'N' & EDG == '12EN' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & EDG == '12EW' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & EDG == '12ES' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & EDG == '12EE' & PEN == '12' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SMEAL12 == 'N' & BIGC == '12CNW' & PEN == '12' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SMEAL12 == 'N' & BIGC == '12CNE' & PEN == '12' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SMEAL12 == 'N' & BIGC == '12CSW' & PEN == '12' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SMEAL12 == 'N' & BIGC == '12CSE' & PEN == '12' & SEC >= 0)
dayfile.cen <- subset(dayfile, SMEAL12 == 'N' & CEN == '12MH' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & CEN == '12MM' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & CEN == '12ML' & PEN == '12' & SEC >= 0)
dayfile.hid <- subset(dayfile, SMEAL12 == 'N' & HID == 'P12HE' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & HID == 'P12HW' & PEN == '12' & SEC >= 0)
dayfile.fs <- subset(dayfile, SMEAL12 == 'N' & FS == 'FS12' & PEN == '12' & SEC >= 0)
#location.sum <- data.frame(c(nrow(dayfile.bot), nrow(dayfile.top), nrow(dayfile.out), nrow(dayfile.edg), nrow(dayfile.bigc), nrow(dayfile.cen), nrow(dayfile.hid)))
location.sum <- data.frame(c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC), sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600))
rownames(location.sum) <- c('<15m', '>15m', 'outer', 'edge', 'NW_corner', 'NE_corner', 'SW_corner', 'SE_corner', 'centre', 'hides', 'feed station')
colnames(location.sum) <- 'Pen12'
# pen 14 location summary
dayfile.bot <- subset(dayfile, SMEAL14 == 'N' & BOT == 'B' & SEC >= 0 & PEN == '14' & SEC >= 0)
dayfile.top <- subset(dayfile, SMEAL14 == 'N' & BOT == 'Z' & PEN == '14' & SEC >= 0)
dayfile.out <- subset(dayfile, SMEAL14 == 'N' & OUT == '14OE' & PEN == '14' & SEC >= 0| SMEAL14 == 'N' & OUT == '14OS' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & OUT == '14ON' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & OUT == '14OW' & PEN == '14' & SEC >= 0)
dayfile.edg <- subset(dayfile, SMEAL14 == 'N' & EDG == '14EN' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & EDG == '14EW' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & EDG == '14ES' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & EDG == '14EE' & PEN == '14' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SMEAL14 == 'N' & BIGC == '14CNW' & PEN == '14' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SMEAL14 == 'N' & BIGC == '14CNE' & PEN == '14' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SMEAL14 == 'N' & BIGC == '14CSW' & PEN == '14' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SMEAL14 == 'N' & BIGC == '14CSE' & PEN == '14' & SEC >= 0)
dayfile.cen <- subset(dayfile, SMEAL14 == 'N' & CEN == '14MH' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & CEN == '14MM' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & CEN == '14ML' & PEN == '14' & SEC >= 0)
dayfile.hid <- subset(dayfile, SMEAL14 == 'N' & HID == 'P14HW' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & HID == 'P14HE' & PEN == '14' & SEC >= 0)
dayfile.fs <- subset(dayfile, SMEAL14 == 'N' & FS == 'FS14' & PEN == '14' & SEC >= 0)
#location.sum$Pen14 <- c(nrow(dayfile.bot), nrow(dayfile.top), nrow(dayfile.out), nrow(dayfile.edg), nrow(dayfile.bigc), nrow(dayfile.cen), nrow(dayfile.hid))
location.sum$Pen14 <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600))
# pen 15 location summary
dayfile.bot <- subset(dayfile, SMEAL15 == 'N' & BOT == 'B' & SEC >= 0 & PEN == '15' & SEC >= 0)
dayfile.top <- subset(dayfile, SMEAL15 == 'N' & BOT == 'Z' & PEN == '15' & SEC >= 0)
dayfile.out <- subset(dayfile, SMEAL15 == 'N' & OUT == '15OE' & PEN == '15' & SEC >= 0| SMEAL15 == 'N' & OUT == '15OS' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & OUT == '15ON' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & OUT == '15OW' & PEN == '15' & SEC >= 0)
dayfile.edg <- subset(dayfile, SMEAL15 == 'N' & EDG == '15EN' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & EDG == '15EW' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & EDG == '15ES' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & EDG == '15EE' & PEN == '15' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SMEAL15 == 'N' & BIGC == '15CNW' & PEN == '15' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SMEAL15 == 'N' & BIGC == '15CNE' & PEN == '15' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SMEAL15 == 'N' & BIGC == '15CSW' & PEN == '15' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SMEAL15 == 'N' & BIGC == '15CSE' & PEN == '15' & SEC >= 0)
dayfile.cen <- subset(dayfile, SMEAL15 == 'N' & CEN == '15MH' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & CEN == '15MM' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & CEN == '15ML' & PEN == '15' & SEC >= 0)
dayfile.hid <- subset(dayfile, SMEAL15 == 'N' & HID == 'P15HW' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & HID == 'P15HE' & PEN == '15' & SEC >= 0)
dayfile.fs <- subset(dayfile, SMEAL15 == 'N' & FS == 'FS15' & PEN == '15' & SEC >= 0)
#location.sum$Pen15 <- c(nrow(dayfile.bot), nrow(dayfile.top), nrow(dayfile.out), nrow(dayfile.edg), nrow(dayfile.bigc), nrow(dayfile.cen), nrow(dayfile.hid))
location.sum$Pen15 <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
location.sum
}
#------ 2b. Batch location summary for multiple day files SMEALOFF------
batch.locationssalfeedoff <- function()
{
files <- list.files(path = workingdir, pattern = '*.csv', all.files = FALSE, recursive = FALSE)
locations.P12 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P12) <- 'ID'
rownames(locations.P12) <- c('P12_<15m', 'P12_>15m', 'P12_outer', 'P12_edge', 'P12_NWcorner', 'P12_NEcorner', 'P12_SWcorner', 'P12_SEcorner', 'P12_centre', 'P12_hides', 'P12_feedstation')
locations.P14 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P14) <- 'ID'
rownames(locations.P14) <- c('P14_<15m', 'P14_>15m', 'P14_outer', 'P14_edge', 'P14_NWcorner', 'P14_NEcorner', 'P14_SWcorner', 'P14_SEcorner', 'P14_centre', 'P14_hides', 'P14_feedstation')
locations.P15 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P15) <- 'ID'
rownames(locations.P15) <- c('P15_<15m', 'P15_>15m', 'P15_outer', 'P15_edge', 'P15_NWcorner', 'P15_NEcorner', 'P15_SWcorner', 'P15_SEcorner', 'P15_centre', 'P15_hides', 'P15_feedstation')
for (i in 1:length(files))
{
dayfile.loc <- files[[i]]
dayfile <- read.csv(dayfile.loc, header = TRUE, sep = ",", colClasses = dayfile.classes)
#SORT BY TIME AND TAG
dayfile <- dayfile[order(dayfile$EchoTime, na.last = FALSE, decreasing = FALSE, method = c("shell")),] # sort by time
dayfile <- dayfile[order(dayfile$Period, na.last = FALSE, decreasing = FALSE, method = c("shell")),] # sort by tag
# pen 12 location summary
dayfile.bot <- subset(dayfile, SMEAL12 == 'N' & BOT == 'B' & PEN == '12' & SEC >= 0)
dayfile.top <- subset(dayfile, SMEAL12 == 'N' & BOT == 'Z' & PEN == '12' & SEC >= 0)
dayfile.out <- subset(dayfile, SMEAL12 == 'N' & OUT == '12OE' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & OUT == '12OS' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & OUT == '12ON' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & OUT == '12OW' & PEN == '12' & SEC >= 0)
dayfile.edg <- subset(dayfile, SMEAL12 == 'N' & EDG == '12EN' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & EDG == '12EW' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & EDG == '12ES' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & EDG == '12EE' & PEN == '12' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SMEAL12 == 'N' & BIGC == '12CNW' & PEN == '12' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SMEAL12 == 'N' & BIGC == '12CNE' & PEN == '12' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SMEAL12 == 'N' & BIGC == '12CSW' & PEN == '12' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SMEAL12 == 'N' & BIGC == '12CSE' & PEN == '12' & SEC >= 0)
dayfile.cen <- subset(dayfile, SMEAL12 == 'N' & CEN == '12MH' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & CEN == '12MM' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & CEN == '12ML' & PEN == '12' & SEC >= 0)
dayfile.hid <- subset(dayfile, SMEAL12 == 'N' & HID == 'P12HW' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & HID == 'P12HE' & PEN == '12' & SEC >= 0)
dayfile.fs <- subset(dayfile, SMEAL12 == 'N' & FS == 'FS12' & PEN == '12' & SEC >= 0)
locations.P12[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
# pen 14 location summary
dayfile.bot <- subset(dayfile, SMEAL14 == 'N' & BOT == 'B' & PEN == '14' & SEC >= 0)
dayfile.top <- subset(dayfile, SMEAL14 == 'N' & BOT == 'Z' & PEN == '14' & SEC >= 0)
dayfile.out <- subset(dayfile, SMEAL14 == 'N' & OUT == '14OE' & PEN == '14' & SEC >= 0| SMEAL14 == 'N' & OUT == '14OS' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & OUT == '14ON' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & OUT == '14OW' & PEN == '14' & SEC >= 0)
dayfile.edg <- subset(dayfile, SMEAL14 == 'N' & EDG == '14EN' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & EDG == '14EW' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & EDG == '14ES' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & EDG == '14EE' & PEN == '14' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SMEAL14 == 'N' & BIGC == '14CNW' & PEN == '14' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SMEAL14 == 'N' & BIGC == '14CNE' & PEN == '14' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SMEAL14 == 'N' & BIGC == '14CSW' & PEN == '14' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SMEAL14 == 'N' & BIGC == '14CSE' & PEN == '14' & SEC >= 0)
dayfile.cen <- subset(dayfile, SMEAL14 == 'N' & CEN == '14MH' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & CEN == '14MM' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & CEN == '14ML' & PEN == '14' & SEC >= 0)
dayfile.hid <- subset(dayfile, SMEAL14 == 'N' & HID == 'P14HW' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & HID == 'P14HE' & PEN == '14' & SEC >= 0)
dayfile.fs <- subset(dayfile, SMEAL14 == 'N' & FS == 'FS14' & PEN == '14' & SEC >= 0)
locations.P14[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
# pen 15 location summary
dayfile.bot <- subset(dayfile, SMEAL15 == 'N' & BOT == 'B' & PEN == '15' & SEC >= 0)
dayfile.top <- subset(dayfile, SMEAL15 == 'N' & BOT == 'Z' & PEN == '15' & SEC >= 0)
dayfile.out <- subset(dayfile, SMEAL15 == 'N' & OUT == '15OE' & PEN == '15' & SEC >= 0| SMEAL15 == 'N' & OUT == '15OS' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & OUT == '15ON' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & OUT == '15OW' & PEN == '15' & SEC >= 0)
dayfile.edg <- subset(dayfile, SMEAL15 == 'N' & EDG == '15EN' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & EDG == '15EW' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & EDG == '15ES' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & EDG == '15EE' & PEN == '15' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SMEAL15 == 'N' & BIGC == '15CNW' & PEN == '15' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SMEAL15 == 'N' & BIGC == '15CNE' & PEN == '15' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SMEAL15 == 'N' & BIGC == '15CSW' & PEN == '15' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SMEAL15 == 'N' & BIGC == '15CSE' & PEN == '15' & SEC >= 0)
dayfile.cen <- subset(dayfile, SMEAL15 == 'N' & CEN == '15MH' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & CEN == '15MM' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & CEN == '15ML' & PEN == '15' & SEC >= 0)
dayfile.hid <- subset(dayfile, SMEAL15 == 'N' & HID == 'P15HW' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & HID == 'P15HE' & PEN == '15' & SEC >= 0)
dayfile.fs <- subset(dayfile, SMEAL15 == 'N' & FS == 'FS15' & PEN == '15' & SEC >= 0)
locations.P15[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
}
location.sum <- rbind(locations.P12, locations.P14, locations.P15)
location.sum$ID <- NULL
location.sum
#loadWorkbook('LocationsOutput.xlsx', create = TRUE)
#writeWorksheetToFile('LocationsOutput.xlsx', location.sum, 'Sheet 1')
write.xlsx(location.sum, 'LocationsOutputSMEALoff.xlsx')
}
#------ 2b. Batch location summary for multiple day files SMEALOFF In the Day Sun == 'D'------
batch.locationssalfeedoffday <- function()
{
files <- list.files(path = workingdir, pattern = '*.csv', all.files = FALSE, recursive = FALSE)
locations.P12 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P12) <- 'ID'
rownames(locations.P12) <- c('P12_<15m', 'P12_>15m', 'P12_outer', 'P12_edge', 'P12_NWcorner', 'P12_NEcorner', 'P12_SWcorner', 'P12_SEcorner', 'P12_centre', 'P12_hides', 'P12_feedstation')
locations.P14 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P14) <- 'ID'
rownames(locations.P14) <- c('P14_<15m', 'P14_>15m', 'P14_outer', 'P14_edge', 'P14_NWcorner', 'P14_NEcorner', 'P14_SWcorner', 'P14_SEcorner', 'P14_centre', 'P14_hides', 'P14_feedstation')
locations.P15 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P15) <- 'ID'
rownames(locations.P15) <- c('P15_<15m', 'P15_>15m', 'P15_outer', 'P15_edge', 'P15_NWcorner', 'P15_NEcorner', 'P15_SWcorner', 'P15_SEcorner', 'P15_centre', 'P15_hides', 'P15_feedstation')
for (i in 1:length(files))
{
dayfile.loc <- files[[i]]
dayfile <- read.csv(dayfile.loc, header = TRUE, sep = ",", colClasses = dayfile.classes)
#SORT BY TIME AND TAG
dayfile <- dayfile[order(dayfile$EchoTime, na.last = FALSE, decreasing = FALSE, method = c("shell")),] # sort by time
dayfile <- dayfile[order(dayfile$Period, na.last = FALSE, decreasing = FALSE, method = c("shell")),] # sort by tag
# pen 12 location summary
dayfile.bot <- subset(dayfile, SUN == 'D' & SMEAL12 == 'N' & BOT == 'B' & PEN == '12' & SEC >= 0)
dayfile.top <- subset(dayfile, SUN == 'D' & SMEAL12 == 'N' & BOT == 'Z' & PEN == '12' & SEC >= 0)
dayfile.out <- subset(dayfile, SUN == 'D' & SMEAL12 == 'N' & OUT == '12OE' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & OUT == '12OS' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & OUT == '12ON' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & OUT == '12OW' & PEN == '12' & SEC >= 0)
dayfile.edg <- subset(dayfile, SUN == 'D' & SMEAL12 == 'N' & EDG == '12EN' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & EDG == '12EW' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & EDG == '12ES' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & EDG == '12EE' & PEN == '12' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SUN == 'D' & SMEAL12 == 'N' & BIGC == '12CNW' & PEN == '12' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SUN == 'D' & SMEAL12 == 'N' & BIGC == '12CNE' & PEN == '12' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SUN == 'D' & SMEAL12 == 'N' & BIGC == '12CSW' & PEN == '12' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SUN == 'D' & SMEAL12 == 'N' & BIGC == '12CSE' & PEN == '12' & SEC >= 0)
dayfile.cen <- subset(dayfile, SUN == 'D' & SMEAL12 == 'N' & CEN == '12MH' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & CEN == '12MM' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & CEN == '12ML' & PEN == '12' & SEC >= 0)
dayfile.hid <- subset(dayfile, SUN == 'D' & SMEAL12 == 'N' & HID == 'P12HW' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & HID == 'P12HE' & PEN == '12' & SEC >= 0)
dayfile.fs <- subset(dayfile, SUN == 'D' & SMEAL12 == 'N' & FS == 'FS12' & PEN == '12' & SEC >= 0)
locations.P12[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
# pen 14 location summary
dayfile.bot <- subset(dayfile, SUN == 'D' & SMEAL14 == 'N' & BOT == 'B' & PEN == '14' & SEC >= 0)
dayfile.top <- subset(dayfile, SUN == 'D' & SMEAL14 == 'N' & BOT == 'Z' & PEN == '14' & SEC >= 0)
dayfile.out <- subset(dayfile, SUN == 'D' & SMEAL14 == 'N' & OUT == '14OE' & PEN == '14' & SEC >= 0| SMEAL14 == 'N' & OUT == '14OS' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & OUT == '14ON' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & OUT == '14OW' & PEN == '14' & SEC >= 0)
dayfile.edg <- subset(dayfile, SUN == 'D' & SMEAL14 == 'N' & EDG == '14EN' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & EDG == '14EW' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & EDG == '14ES' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & EDG == '14EE' & PEN == '14' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SUN == 'D' & SMEAL14 == 'N' & BIGC == '14CNW' & PEN == '14' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SUN == 'D' & SMEAL14 == 'N' & BIGC == '14CNE' & PEN == '14' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SUN == 'D' & SMEAL14 == 'N' & BIGC == '14CSW' & PEN == '14' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SUN == 'D' & SMEAL14 == 'N' & BIGC == '14CSE' & PEN == '14' & SEC >= 0)
dayfile.cen <- subset(dayfile, SUN == 'D' & SMEAL14 == 'N' & CEN == '14MH' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & CEN == '14MM' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & CEN == '14ML' & PEN == '14' & SEC >= 0)
dayfile.hid <- subset(dayfile, SUN == 'D' & SMEAL14 == 'N' & HID == 'P14HW' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & HID == 'P14HE' & PEN == '14' & SEC >= 0)
dayfile.fs <- subset(dayfile, SUN == 'D' & SMEAL14 == 'N' & FS == 'FS14' & PEN == '14' & SEC >= 0)
locations.P14[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
# pen 15 location summary
dayfile.bot <- subset(dayfile, SUN == 'D' & SMEAL15 == 'N' & BOT == 'B' & PEN == '15' & SEC >= 0)
dayfile.top <- subset(dayfile, SUN == 'D' & SMEAL15 == 'N' & BOT == 'Z' & PEN == '15' & SEC >= 0)
dayfile.out <- subset(dayfile, SUN == 'D' & SMEAL15 == 'N' & OUT == '15OE' & PEN == '15' & SEC >= 0| SMEAL15 == 'N' & OUT == '15OS' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & OUT == '15ON' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & OUT == '15OW' & PEN == '15' & SEC >= 0)
dayfile.edg <- subset(dayfile, SUN == 'D' & SMEAL15 == 'N' & EDG == '15EN' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & EDG == '15EW' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & EDG == '15ES' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & EDG == '15EE' & PEN == '15' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SUN == 'D' & SMEAL15 == 'N' & BIGC == '15CNW' & PEN == '15' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SUN == 'D' & SMEAL15 == 'N' & BIGC == '15CNE' & PEN == '15' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SUN == 'D' & SMEAL15 == 'N' & BIGC == '15CSW' & PEN == '15' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SUN == 'D' & SMEAL15 == 'N' & BIGC == '15CSE' & PEN == '15' & SEC >= 0)
dayfile.cen <- subset(dayfile, SUN == 'D' & SMEAL15 == 'N' & CEN == '15MH' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & CEN == '15MM' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & CEN == '15ML' & PEN == '15' & SEC >= 0)
dayfile.hid <- subset(dayfile, SUN == 'D' & SMEAL15 == 'N' & HID == 'P15HW' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & HID == 'P15HE' & PEN == '15' & SEC >= 0)
dayfile.fs <- subset(dayfile, SUN == 'D' & SMEAL15 == 'N' & FS == 'FS15' & PEN == '15' & SEC >= 0)
locations.P15[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
}
location.sum <- rbind(locations.P12, locations.P14, locations.P15)
location.sum$ID <- NULL
location.sum
#loadWorkbook('LocationsOutput.xlsx', create = TRUE)
#writeWorksheetToFile('LocationsOutput.xlsx', location.sum, 'Sheet 1')
write.xlsx(location.sum, 'LocationsOutputSMEALoffday.xlsx')
}
#------ 2b. Batch location summary for multiple day files SMEALOFF In the Night Sun == 'N'------
batch.locationssalfeedoffnight <- function()
{
files <- list.files(path = workingdir, pattern = '*.csv', all.files = FALSE, recursive = FALSE)
locations.P12 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P12) <- 'ID'
rownames(locations.P12) <- c('P12_<15m', 'P12_>15m', 'P12_outer', 'P12_edge', 'P12_NWcorner', 'P12_NEcorner', 'P12_SWcorner', 'P12_SEcorner', 'P12_centre', 'P12_hides', 'P12_feedstation')
locations.P14 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P14) <- 'ID'
rownames(locations.P14) <- c('P14_<15m', 'P14_>15m', 'P14_outer', 'P14_edge', 'P14_NWcorner', 'P14_NEcorner', 'P14_SWcorner', 'P14_SEcorner', 'P14_centre', 'P14_hides', 'P14_feedstation')
locations.P15 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P15) <- 'ID'
rownames(locations.P15) <- c('P15_<15m', 'P15_>15m', 'P15_outer', 'P15_edge', 'P15_NWcorner', 'P15_NEcorner', 'P15_SWcorner', 'P15_SEcorner', 'P15_centre', 'P15_hides', 'P15_feedstation')
for (i in 1:length(files))
{
dayfile.loc <- files[[i]]
dayfile <- read.csv(dayfile.loc, header = TRUE, sep = ",", colClasses = dayfile.classes)
#SORT BY TIME AND TAG
dayfile <- dayfile[order(dayfile$EchoTime, na.last = FALSE, decreasing = FALSE, method = c("shell")),] # sort by time
dayfile <- dayfile[order(dayfile$Period, na.last = FALSE, decreasing = FALSE, method = c("shell")),] # sort by tag
# pen 12 location summary
dayfile.bot <- subset(dayfile, SUN == 'N' & SMEAL12 == 'N' & BOT == 'B' & PEN == '12' & SEC >= 0)
dayfile.top <- subset(dayfile, SUN == 'N' & SMEAL12 == 'N' & BOT == 'Z' & PEN == '12' & SEC >= 0)
dayfile.out <- subset(dayfile, SUN == 'N' & SMEAL12 == 'N' & OUT == '12OE' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & OUT == '12OS' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & OUT == '12ON' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & OUT == '12OW' & PEN == '12' & SEC >= 0)
dayfile.edg <- subset(dayfile, SUN == 'N' & SMEAL12 == 'N' & EDG == '12EN' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & EDG == '12EW' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & EDG == '12ES' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & EDG == '12EE' & PEN == '12' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SUN == 'N' & SMEAL12 == 'N' & BIGC == '12CNW' & PEN == '12' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SUN == 'N' & SMEAL12 == 'N' & BIGC == '12CNE' & PEN == '12' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SUN == 'N' & SMEAL12 == 'N' & BIGC == '12CSW' & PEN == '12' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SUN == 'N' & SMEAL12 == 'N' & BIGC == '12CSE' & PEN == '12' & SEC >= 0)
dayfile.cen <- subset(dayfile, SUN == 'N' & SMEAL12 == 'N' & CEN == '12MH' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & CEN == '12MM' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & CEN == '12ML' & PEN == '12' & SEC >= 0)
dayfile.hid <- subset(dayfile, SUN == 'N' & SMEAL12 == 'N' & HID == 'P12HW' & PEN == '12' & SEC >= 0 | SMEAL12 == 'N' & HID == 'P12HE' & PEN == '12' & SEC >= 0)
dayfile.fs <- subset(dayfile, SUN == 'N' & SMEAL12 == 'N' & FS == 'FS12' & PEN == '12' & SEC >= 0)
locations.P12[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
# pen 14 location summary
dayfile.bot <- subset(dayfile, SUN == 'N' & SMEAL14 == 'N' & BOT == 'B' & PEN == '14' & SEC >= 0)
dayfile.top <- subset(dayfile, SUN == 'N' & SMEAL14 == 'N' & BOT == 'Z' & PEN == '14' & SEC >= 0)
dayfile.out <- subset(dayfile, SUN == 'N' & SMEAL14 == 'N' & OUT == '14OE' & PEN == '14' & SEC >= 0| SMEAL14 == 'N' & OUT == '14OS' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & OUT == '14ON' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & OUT == '14OW' & PEN == '14' & SEC >= 0)
dayfile.edg <- subset(dayfile, SUN == 'N' & SMEAL14 == 'N' & EDG == '14EN' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & EDG == '14EW' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & EDG == '14ES' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & EDG == '14EE' & PEN == '14' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SUN == 'N' & SMEAL14 == 'N' & BIGC == '14CNW' & PEN == '14' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SUN == 'N' & SMEAL14 == 'N' & BIGC == '14CNE' & PEN == '14' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SUN == 'N' & SMEAL14 == 'N' & BIGC == '14CSW' & PEN == '14' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SUN == 'N' & SMEAL14 == 'N' & BIGC == '14CSE' & PEN == '14' & SEC >= 0)
dayfile.cen <- subset(dayfile, SUN == 'N' & SMEAL14 == 'N' & CEN == '14MH' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & CEN == '14MM' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & CEN == '14ML' & PEN == '14' & SEC >= 0)
dayfile.hid <- subset(dayfile, SUN == 'N' & SMEAL14 == 'N' & HID == 'P14HW' & PEN == '14' & SEC >= 0 | SMEAL14 == 'N' & HID == 'P14HE' & PEN == '14' & SEC >= 0)
dayfile.fs <- subset(dayfile, SUN == 'N' & SMEAL14 == 'N' & FS == 'FS14' & PEN == '14' & SEC >= 0)
locations.P14[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
# pen 15 location summary
dayfile.bot <- subset(dayfile, SUN == 'N' & SMEAL15 == 'N' & BOT == 'B' & PEN == '15' & SEC >= 0)
dayfile.top <- subset(dayfile, SUN == 'N' & SMEAL15 == 'N' & BOT == 'Z' & PEN == '15' & SEC >= 0)
dayfile.out <- subset(dayfile, SUN == 'N' & SMEAL15 == 'N' & OUT == '15OE' & PEN == '15' & SEC >= 0| SMEAL15 == 'N' & OUT == '15OS' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & OUT == '15ON' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & OUT == '15OW' & PEN == '15' & SEC >= 0)
dayfile.edg <- subset(dayfile, SUN == 'N' & SMEAL15 == 'N' & EDG == '15EN' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & EDG == '15EW' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & EDG == '15ES' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & EDG == '15EE' & PEN == '15' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SUN == 'N' & SMEAL15 == 'N' & BIGC == '15CNW' & PEN == '15' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SUN == 'N' & SMEAL15 == 'N' & BIGC == '15CNE' & PEN == '15' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SUN == 'N' & SMEAL15 == 'N' & BIGC == '15CSW' & PEN == '15' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SUN == 'N' & SMEAL15 == 'N' & BIGC == '15CSE' & PEN == '15' & SEC >= 0)
dayfile.cen <- subset(dayfile, SUN == 'N' & SMEAL15 == 'N' & CEN == '15MH' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & CEN == '15MM' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & CEN == '15ML' & PEN == '15' & SEC >= 0)
dayfile.hid <- subset(dayfile, SUN == 'N' & SMEAL15 == 'N' & HID == 'P15HW' & PEN == '15' & SEC >= 0 | SMEAL15 == 'N' & HID == 'P15HE' & PEN == '15' & SEC >= 0)
dayfile.fs <- subset(dayfile, SUN == 'N' & SMEAL15 == 'N' & FS == 'FS15' & PEN == '15' & SEC >= 0)
locations.P15[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
}
location.sum <- rbind(locations.P12, locations.P14, locations.P15)
location.sum$ID <- NULL
location.sum
#loadWorkbook('LocationsOutput.xlsx', create = TRUE)
#writeWorksheetToFile('LocationsOutput.xlsx', location.sum, 'Sheet 1')
write.xlsx(location.sum, 'LocationsOutputSMEALoffnight.xlsx')
}
##----------------------------------------------REDO SMEAL Coding for Day off and Night--------------
#------ 2b. Batch location summary for multiple day files SMEALOFF In the Day Sun == 'D'------
batch.locationssalfeedoffday2 <- function()
{
files <- list.files(path = workingdir, pattern = '*.csv', all.files = FALSE, recursive = FALSE)
locations.P12 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P12) <- 'ID'
rownames(locations.P12) <- c('P12_<15m', 'P12_>15m', 'P12_outer', 'P12_edge', 'P12_NWcorner', 'P12_NEcorner', 'P12_SWcorner', 'P12_SEcorner', 'P12_centre', 'P12_hides', 'P12_feedstation')
locations.P14 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P14) <- 'ID'
rownames(locations.P14) <- c('P14_<15m', 'P14_>15m', 'P14_outer', 'P14_edge', 'P14_NWcorner', 'P14_NEcorner', 'P14_SWcorner', 'P14_SEcorner', 'P14_centre', 'P14_hides', 'P14_feedstation')
locations.P15 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P15) <- 'ID'
rownames(locations.P15) <- c('P15_<15m', 'P15_>15m', 'P15_outer', 'P15_edge', 'P15_NWcorner', 'P15_NEcorner', 'P15_SWcorner', 'P15_SEcorner', 'P15_centre', 'P15_hides', 'P15_feedstation')
for (i in 1:length(files))
{
dayfile.loc <- files[[i]]
dayfile <- read.csv(dayfile.loc, header = TRUE, sep = ",", colClasses = dayfile.classes)
#SORT BY TIME AND TAG
dayfile <- dayfile[order(dayfile$EchoTime, na.last = FALSE, decreasing = FALSE, method = c("shell")),] # sort by time
dayfile <- dayfile[order(dayfile$Period, na.last = FALSE, decreasing = FALSE, method = c("shell")),] # sort by tag
# pen 12 location summary
dayfile.bot <- subset(dayfile, SUN == 'D' & SMEAL12 == 'N' & BOT == 'B' & PEN == '12' & SEC >= 0)
dayfile.top <- subset(dayfile, SUN == 'D' & SMEAL12 == 'N' & BOT == 'Z' & PEN == '12' & SEC >= 0)
dayfile.out <- subset(dayfile, SUN == 'D' & SMEAL12 == 'N' & OUT == '12OE' & PEN == '12' & SEC >= 0 | SUN == 'D' & SMEAL12 == 'N' & OUT == '12OS' & PEN == '12' & SEC >= 0 | SUN == 'D' & SMEAL12 == 'N' & OUT == '12ON' & PEN == '12' & SEC >= 0 | SUN == 'D' & SMEAL12 == 'N' & OUT == '12OW' & PEN == '12' & SEC >= 0)
dayfile.edg <- subset(dayfile, SUN == 'D' & SMEAL12 == 'N' & EDG == '12EN' & PEN == '12' & SEC >= 0 | SUN == 'D' & SMEAL12 == 'N' & EDG == '12EW' & PEN == '12' & SEC >= 0 | SUN == 'D' & SMEAL12 == 'N' & EDG == '12ES' & PEN == '12' & SEC >= 0 | SUN == 'D' & SMEAL12 == 'N' & EDG == '12EE' & PEN == '12' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SUN == 'D' & SMEAL12 == 'N' & BIGC == '12CNW' & PEN == '12' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SUN == 'D' & SMEAL12 == 'N' & BIGC == '12CNE' & PEN == '12' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SUN == 'D' & SMEAL12 == 'N' & BIGC == '12CSW' & PEN == '12' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SUN == 'D' & SMEAL12 == 'N' & BIGC == '12CSE' & PEN == '12' & SEC >= 0)
dayfile.cen <- subset(dayfile, SUN == 'D' & SMEAL12 == 'N' & CEN == '12MH' & PEN == '12' & SEC >= 0 | SUN == 'D' & SMEAL12 == 'N' & CEN == '12MM' & PEN == '12' & SEC >= 0 | SUN == 'D' & SMEAL12 == 'N' & CEN == '12ML' & PEN == '12' & SEC >= 0)
dayfile.hid <- subset(dayfile, SUN == 'D' & SMEAL12 == 'N' & HID == 'P12HW' & PEN == '12' & SEC >= 0 | SUN == 'D' & SMEAL12 == 'N' & HID == 'P12HE' & PEN == '12' & SEC >= 0)
dayfile.fs <- subset(dayfile, SUN == 'D' & SMEAL12 == 'N' & FS == 'FS12' & PEN == '12' & SEC >= 0)
locations.P12[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
# pen 14 location summary
dayfile.bot <- subset(dayfile, SUN == 'D' & SMEAL14 == 'N' & BOT == 'B' & PEN == '14' & SEC >= 0)
dayfile.top <- subset(dayfile, SUN == 'D' & SMEAL14 == 'N' & BOT == 'Z' & PEN == '14' & SEC >= 0)
dayfile.out <- subset(dayfile, SUN == 'D' & SMEAL14 == 'N' & OUT == '14OE' & PEN == '14' & SEC >= 0| SUN == 'D' & SMEAL14 == 'N' & OUT == '14OS' & PEN == '14' & SEC >= 0 | SUN == 'D' & SMEAL14 == 'N' & OUT == '14ON' & PEN == '14' & SEC >= 0 | SUN == 'D' & SMEAL14 == 'N' & OUT == '14OW' & PEN == '14' & SEC >= 0)
dayfile.edg <- subset(dayfile, SUN == 'D' & SMEAL14 == 'N' & EDG == '14EN' & PEN == '14' & SEC >= 0 | SUN == 'D' & SMEAL14 == 'N' & EDG == '14EW' & PEN == '14' & SEC >= 0 | SUN == 'D' & SMEAL14 == 'N' & EDG == '14ES' & PEN == '14' & SEC >= 0 | SUN == 'D' & SMEAL14 == 'N' & EDG == '14EE' & PEN == '14' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SUN == 'D' & SMEAL14 == 'N' & BIGC == '14CNW' & PEN == '14' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SUN == 'D' & SMEAL14 == 'N' & BIGC == '14CNE' & PEN == '14' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SUN == 'D' & SMEAL14 == 'N' & BIGC == '14CSW' & PEN == '14' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SUN == 'D' & SMEAL14 == 'N' & BIGC == '14CSE' & PEN == '14' & SEC >= 0)
dayfile.cen <- subset(dayfile, SUN == 'D' & SMEAL14 == 'N' & CEN == '14MH' & PEN == '14' & SEC >= 0 | SUN == 'D' & SMEAL14 == 'N' & CEN == '14MM' & PEN == '14' & SEC >= 0 | SUN == 'D' & SMEAL14 == 'N' & CEN == '14ML' & PEN == '14' & SEC >= 0)
dayfile.hid <- subset(dayfile, SUN == 'D' & SMEAL14 == 'N' & HID == 'P14HW' & PEN == '14' & SEC >= 0 | SUN == 'D' & SMEAL14 == 'N' & HID == 'P14HE' & PEN == '14' & SEC >= 0)
dayfile.fs <- subset(dayfile, SUN == 'D' & SMEAL14 == 'N' & FS == 'FS14' & PEN == '14' & SEC >= 0)
locations.P14[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
# pen 15 location summary
dayfile.bot <- subset(dayfile, SUN == 'D' & SMEAL15 == 'N' & BOT == 'B' & PEN == '15' & SEC >= 0)
dayfile.top <- subset(dayfile, SUN == 'D' & SMEAL15 == 'N' & BOT == 'Z' & PEN == '15' & SEC >= 0)
dayfile.out <- subset(dayfile, SUN == 'D' & SMEAL15 == 'N' & OUT == '15OE' & PEN == '15' & SEC >= 0| SUN == 'D' & SMEAL15 == 'N' & OUT == '15OS' & PEN == '15' & SEC >= 0 | SUN == 'D' & SMEAL15 == 'N' & OUT == '15ON' & PEN == '15' & SEC >= 0 | SUN == 'D' & SMEAL15 == 'N' & OUT == '15OW' & PEN == '15' & SEC >= 0)
dayfile.edg <- subset(dayfile, SUN == 'D' & SMEAL15 == 'N' & EDG == '15EN' & PEN == '15' & SEC >= 0 | SUN == 'D' & SMEAL15 == 'N' & EDG == '15EW' & PEN == '15' & SEC >= 0 | SUN == 'D' & SMEAL15 == 'N' & EDG == '15ES' & PEN == '15' & SEC >= 0 | SUN == 'D' & SMEAL15 == 'N' & EDG == '15EE' & PEN == '15' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SUN == 'D' & SMEAL15 == 'N' & BIGC == '15CNW' & PEN == '15' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SUN == 'D' & SMEAL15 == 'N' & BIGC == '15CNE' & PEN == '15' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SUN == 'D' & SMEAL15 == 'N' & BIGC == '15CSW' & PEN == '15' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SUN == 'D' & SMEAL15 == 'N' & BIGC == '15CSE' & PEN == '15' & SEC >= 0)
dayfile.cen <- subset(dayfile, SUN == 'D' & SMEAL15 == 'N' & CEN == '15MH' & PEN == '15' & SEC >= 0 | SUN == 'D' & SMEAL15 == 'N' & CEN == '15MM' & PEN == '15' & SEC >= 0 | SUN == 'D' & SMEAL15 == 'N' & CEN == '15ML' & PEN == '15' & SEC >= 0)
dayfile.hid <- subset(dayfile, SUN == 'D' & SMEAL15 == 'N' & HID == 'P15HW' & PEN == '15' & SEC >= 0 | SUN == 'D' & SMEAL15 == 'N' & HID == 'P15HE' & PEN == '15' & SEC >= 0)
dayfile.fs <- subset(dayfile, SUN == 'D' & SMEAL15 == 'N' & FS == 'FS15' & PEN == '15' & SEC >= 0)
locations.P15[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
}
location.sum <- rbind(locations.P12, locations.P14, locations.P15)
location.sum$ID <- NULL
location.sum
#loadWorkbook('LocationsOutput.xlsx', create = TRUE)
#writeWorksheetToFile('LocationsOutput.xlsx', location.sum, 'Sheet 1')
write.xlsx(location.sum, 'LocationsOutputSMEALoffday2.xlsx')
}
#------ 2b. Batch location summary for multiple day files SMEALOFF In the Night Sun == 'N'------
batch.locationssalfeedoffnight2 <- function()
{
files <- list.files(path = workingdir, pattern = '*.csv', all.files = FALSE, recursive = FALSE)
locations.P12 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P12) <- 'ID'
rownames(locations.P12) <- c('P12_<15m', 'P12_>15m', 'P12_outer', 'P12_edge', 'P12_NWcorner', 'P12_NEcorner', 'P12_SWcorner', 'P12_SEcorner', 'P12_centre', 'P12_hides', 'P12_feedstation')
locations.P14 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P14) <- 'ID'
rownames(locations.P14) <- c('P14_<15m', 'P14_>15m', 'P14_outer', 'P14_edge', 'P14_NWcorner', 'P14_NEcorner', 'P14_SWcorner', 'P14_SEcorner', 'P14_centre', 'P14_hides', 'P14_feedstation')
locations.P15 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P15) <- 'ID'
rownames(locations.P15) <- c('P15_<15m', 'P15_>15m', 'P15_outer', 'P15_edge', 'P15_NWcorner', 'P15_NEcorner', 'P15_SWcorner', 'P15_SEcorner', 'P15_centre', 'P15_hides', 'P15_feedstation')
for (i in 1:length(files))
{
dayfile.loc <- files[[i]]
dayfile <- read.csv(dayfile.loc, header = TRUE, sep = ",", colClasses = dayfile.classes)
#SORT BY TIME AND TAG
dayfile <- dayfile[order(dayfile$EchoTime, na.last = FALSE, decreasing = FALSE, method = c("shell")),] # sort by time
dayfile <- dayfile[order(dayfile$Period, na.last = FALSE, decreasing = FALSE, method = c("shell")),] # sort by tag
# pen 12 location summary
dayfile.bot <- subset(dayfile, SUN == 'N' & SMEAL12 == 'N' & BOT == 'B' & PEN == '12' & SEC >= 0)
dayfile.top <- subset(dayfile, SUN == 'N' & SMEAL12 == 'N' & BOT == 'Z' & PEN == '12' & SEC >= 0)
dayfile.out <- subset(dayfile, SUN == 'N' & SMEAL12 == 'N' & OUT == '12OE' & PEN == '12' & SEC >= 0 | SUN == 'N' &SMEAL12 == 'N' & OUT == '12OS' & PEN == '12' & SEC >= 0 | SUN == 'N' & SMEAL12 == 'N' & OUT == '12ON' & PEN == '12' & SEC >= 0 | SUN == 'N' & SMEAL12 == 'N' & OUT == '12OW' & PEN == '12' & SEC >= 0)
dayfile.edg <- subset(dayfile, SUN == 'N' & SMEAL12 == 'N' & EDG == '12EN' & PEN == '12' & SEC >= 0 | SUN == 'N' &SMEAL12 == 'N' & EDG == '12EW' & PEN == '12' & SEC >= 0 | SUN == 'N' & SMEAL12 == 'N' & EDG == '12ES' & PEN == '12' & SEC >= 0 | SUN == 'N' & SMEAL12 == 'N' & EDG == '12EE' & PEN == '12' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SUN == 'N' & SMEAL12 == 'N' & BIGC == '12CNW' & PEN == '12' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SUN == 'N' & SMEAL12 == 'N' & BIGC == '12CNE' & PEN == '12' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SUN == 'N' & SMEAL12 == 'N' & BIGC == '12CSW' & PEN == '12' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SUN == 'N' & SMEAL12 == 'N' & BIGC == '12CSE' & PEN == '12' & SEC >= 0)
dayfile.cen <- subset(dayfile, SUN == 'N' & SMEAL12 == 'N' & CEN == '12MH' & PEN == '12' & SEC >= 0 | SUN == 'N' & SMEAL12 == 'N' & CEN == '12MM' & PEN == '12' & SEC >= 0 | SUN == 'N' & SMEAL12 == 'N' & CEN == '12ML' & PEN == '12' & SEC >= 0)
dayfile.hid <- subset(dayfile, SUN == 'N' & SMEAL12 == 'N' & HID == 'P12HW' & PEN == '12' & SEC >= 0 | SUN == 'N' & SMEAL12 == 'N' & HID == 'P12HE' & PEN == '12' & SEC >= 0)
dayfile.fs <- subset(dayfile, SUN == 'N' & SMEAL12 == 'N' & FS == 'FS12' & PEN == '12' & SEC >= 0)
locations.P12[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
# pen 14 location summary
dayfile.bot <- subset(dayfile, SUN == 'N' & SMEAL14 == 'N' & BOT == 'B' & PEN == '14' & SEC >= 0)
dayfile.top <- subset(dayfile, SUN == 'N' & SMEAL14 == 'N' & BOT == 'Z' & PEN == '14' & SEC >= 0)
dayfile.out <- subset(dayfile, SUN == 'N' & SMEAL14 == 'N' & OUT == '14OE' & PEN == '14' & SEC >= 0| SUN == 'N' & SMEAL14 == 'N' & OUT == '14OS' & PEN == '14' & SEC >= 0 | SUN == 'N' & SMEAL14 == 'N' & OUT == '14ON' & PEN == '14' & SEC >= 0 | SUN == 'N' & SMEAL14 == 'N' & OUT == '14OW' & PEN == '14' & SEC >= 0)
dayfile.edg <- subset(dayfile, SUN == 'N' & SMEAL14 == 'N' & EDG == '14EN' & PEN == '14' & SEC >= 0 | SUN == 'N' & SMEAL14 == 'N' & EDG == '14EW' & PEN == '14' & SEC >= 0 | SUN == 'N' & SMEAL14 == 'N' & EDG == '14ES' & PEN == '14' & SEC >= 0 | SUN == 'N' & SMEAL14 == 'N' & EDG == '14EE' & PEN == '14' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SUN == 'N' & SMEAL14 == 'N' & BIGC == '14CNW' & PEN == '14' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SUN == 'N' & SMEAL14 == 'N' & BIGC == '14CNE' & PEN == '14' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SUN == 'N' & SMEAL14 == 'N' & BIGC == '14CSW' & PEN == '14' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SUN == 'N' & SMEAL14 == 'N' & BIGC == '14CSE' & PEN == '14' & SEC >= 0)
dayfile.cen <- subset(dayfile, SUN == 'N' & SMEAL14 == 'N' & CEN == '14MH' & PEN == '14' & SEC >= 0 | SUN == 'N' & SMEAL14 == 'N' & CEN == '14MM' & PEN == '14' & SEC >= 0 | SUN == 'N' & SMEAL14 == 'N' & CEN == '14ML' & PEN == '14' & SEC >= 0)
dayfile.hid <- subset(dayfile, SUN == 'N' & SMEAL14 == 'N' & HID == 'P14HW' & PEN == '14' & SEC >= 0 | SUN == 'N' & SMEAL14 == 'N' & HID == 'P14HE' & PEN == '14' & SEC >= 0)
dayfile.fs <- subset(dayfile, SUN == 'N' & SMEAL14 == 'N' & FS == 'FS14' & PEN == '14' & SEC >= 0)
locations.P14[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
# pen 15 location summary
dayfile.bot <- subset(dayfile, SUN == 'N' & SMEAL15 == 'N' & BOT == 'B' & SEC >= 0 & PEN == '15' & SEC >= 0)
dayfile.top <- subset(dayfile, SUN == 'N' & SMEAL15 == 'N' & BOT == 'Z' & PEN == '15' & SEC >= 0)
dayfile.out <- subset(dayfile, SUN == 'N' & SMEAL15 == 'N' & OUT == '15OE' & PEN == '15' & SEC >= 0| SUN == 'N' & SMEAL15 == 'N' & OUT == '15OS' & PEN == '15' & SEC >= 0 | SUN == 'N' & SMEAL15 == 'N' & OUT == '15ON' & PEN == '15' & SEC >= 0 | SUN == 'N' & SMEAL15 == 'N' & OUT == '15OW' & PEN == '15' & SEC >= 0)
dayfile.edg <- subset(dayfile, SUN == 'N' & SMEAL15 == 'N' & EDG == '15EN' & PEN == '15' & SEC >= 0 | SUN == 'N' & SMEAL15 == 'N' & EDG == '15EW' & PEN == '15' & SEC >= 0 | SUN == 'N' & SMEAL15 == 'N' & EDG == '15ES' & PEN == '15' & SEC >= 0 | SUN == 'N' & SMEAL15 == 'N' & EDG == '15EE' & PEN == '15' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SUN == 'N' & SMEAL15 == 'N' & BIGC == '15CNW' & PEN == '15' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SUN == 'N' & SMEAL15 == 'N' & BIGC == '15CNE' & PEN == '15' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SUN == 'N' & SMEAL15 == 'N' & BIGC == '15CSW' & PEN == '15' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SUN == 'N' & SMEAL15 == 'N' & BIGC == '15CSE' & PEN == '15' & SEC >= 0)
dayfile.cen <- subset(dayfile, SUN == 'N' & SMEAL15 == 'N' & CEN == '15MH' & PEN == '15' & SEC >= 0 | SUN == 'N' & SMEAL15 == 'N' & CEN == '15MM' & PEN == '15' & SEC >= 0 | SUN == 'N' & SMEAL15 == 'N' & CEN == '15ML' & PEN == '15' & SEC >= 0)
dayfile.hid <- subset(dayfile, SUN == 'N' & SMEAL15 == 'N' & HID == 'P15HW' & PEN == '15' & SEC >= 0 | SUN == 'N' & SMEAL15 == 'N' & HID == 'P15HE' & PEN == '15' & SEC >= 0)
dayfile.fs <- subset(dayfile, SUN == 'N' & SMEAL15 == 'N' & FS == 'FS15' & PEN == '15' & SEC >= 0)
locations.P15[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
}
location.sum <- rbind(locations.P12, locations.P14, locations.P15)
location.sum$ID <- NULL
location.sum
#loadWorkbook('LocationsOutput.xlsx', create = TRUE)
#writeWorksheetToFile('LocationsOutput.xlsx', location.sum, 'Sheet 1')
write.xlsx(location.sum, 'LocationsOutputSMEALoffnight2.xlsx')
}
#------ 2b. Batch location summary for multiple day files Before Net Swings: C ------
batch.locationsnetswingdayC <- function()
{
files <- list.files(path = workingdir, pattern = '*.csv', all.files = FALSE, recursive = FALSE)
locations.P12 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P12) <- 'ID'
rownames(locations.P12) <- c('P12_<15m', 'P12_>15m', 'P12_outer', 'P12_edge', 'P12_NWcorner', 'P12_NEcorner', 'P12_SWcorner', 'P12_SEcorner', 'P12_centre', 'P12_hides', 'P12_feedstation')
locations.P14 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P14) <- 'ID'
rownames(locations.P14) <- c('P14_<15m', 'P14_>15m', 'P14_outer', 'P14_edge', 'P14_NWcorner', 'P14_NEcorner', 'P14_SWcorner', 'P14_SEcorner', 'P14_centre', 'P14_hides', 'P14_feedstation')
locations.P15 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P15) <- 'ID'
rownames(locations.P15) <- c('P15_<15m', 'P15_>15m', 'P15_outer', 'P15_edge', 'P15_NWcorner', 'P15_NEcorner', 'P15_SWcorner', 'P15_SEcorner', 'P15_centre', 'P15_hides', 'P15_feedstation')
for (i in 1:length(files))
{
dayfile.loc <- files[[i]]
dayfile <- read.csv(dayfile.loc, header = TRUE, sep = ",", colClasses = dayfile.classes)
#SORT BY TIME AND TAG
dayfile <- dayfile[order(dayfile$EchoTime, na.last = FALSE, decreasing = FALSE, method = c("shell")),] # sort by time
dayfile <- dayfile[order(dayfile$Period, na.last = FALSE, decreasing = FALSE, method = c("shell")),] # sort by tag
# pen 12 location summary
dayfile.bot <- subset(dayfile, SUN == 'D' & BIOF12 == 'C' & BOT == 'B' & PEN == '12' & SEC >= 0)
dayfile.top <- subset(dayfile, SUN == 'D' & BIOF12 == 'C' & BOT == 'Z' & PEN == '12' & SEC >= 0)
dayfile.out <- subset(dayfile, SUN == 'D' & BIOF12 == 'C' & OUT == '12OE' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'C' & OUT == '12OS' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'C' & OUT == '12ON' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'C' & OUT == '12OW' & PEN == '12' & SEC >= 0)
dayfile.edg <- subset(dayfile, SUN == 'D' & BIOF12 == 'C' & EDG == '12EN' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'C' & EDG == '12EW' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'C' & EDG == '12ES' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'C' & EDG == '12EE' & PEN == '12' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SUN == 'D' & BIOF12 == 'C' & BIGC == '12CNW' & PEN == '12' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SUN == 'D' & BIOF12 == 'C' & BIGC == '12CNE' & PEN == '12' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SUN == 'D' & BIOF12 == 'C' & BIGC == '12CSW' & PEN == '12' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SUN == 'D' & BIOF12 == 'C' & BIGC == '12CSE' & PEN == '12' & SEC >= 0)
dayfile.cen <- subset(dayfile, SUN == 'D' & BIOF12 == 'C' & CEN == '12MH' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'C' & CEN == '12MM' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'C' & CEN == '12ML' & PEN == '12' & SEC >= 0)
dayfile.hid <- subset(dayfile, SUN == 'D' & BIOF12 == 'C' & HID == 'P12HW' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'C' & HID == 'P12HE' & PEN == '12' & SEC >= 0)
dayfile.fs <- subset(dayfile, SUN == 'D' & BIOF12 == 'C' & FS == 'FS12' & PEN == '12' & SEC >= 0)
locations.P12[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
# pen 14 location summary
dayfile.bot <- subset(dayfile, SUN == 'D' & BIOF14 == 'C' & BOT == 'B' & PEN == '14' & SEC >= 0)
dayfile.top <- subset(dayfile, SUN == 'D' & BIOF14 == 'C' & BOT == 'Z' & PEN == '14' & SEC >= 0)
dayfile.out <- subset(dayfile, SUN == 'D' & BIOF14 == 'C' & OUT == '14OE' & PEN == '14' & SEC >= 0| SUN == 'D' & BIOF14 == 'C' & OUT == '14OS' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'C' & OUT == '14ON' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'C' & OUT == '14OW' & PEN == '14' & SEC >= 0)
dayfile.edg <- subset(dayfile, SUN == 'D' & BIOF14 == 'C' & EDG == '14EN' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'C' & EDG == '14EW' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'C' & EDG == '14ES' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'C' & EDG == '14EE' & PEN == '14' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SUN == 'D' & BIOF14 == 'C' & BIGC == '14CNW' & PEN == '14' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SUN == 'D' & BIOF14 == 'C' & BIGC == '14CNE' & PEN == '14' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SUN == 'D' & BIOF14 == 'C' & BIGC == '14CSW' & PEN == '14' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SUN == 'D' & BIOF14 == 'C' & BIGC == '14CSE' & PEN == '14' & SEC >= 0)
dayfile.cen <- subset(dayfile, SUN == 'D' & BIOF14 == 'C' & CEN == '14MH' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'C' & CEN == '14MM' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'C' & CEN == '14ML' & PEN == '14' & SEC >= 0)
dayfile.hid <- subset(dayfile, SUN == 'D' & BIOF14 == 'C' & HID == 'P14HW' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'C' & HID == 'P14HE' & PEN == '14' & SEC >= 0)
dayfile.fs <- subset(dayfile, SUN == 'D' & BIOF14 == 'C' & FS == 'FS14' & PEN == '14' & SEC >= 0)
locations.P14[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
# pen 15 location summary
dayfile.bot <- subset(dayfile, SUN == 'D' & BIOF15 == 'C' & BOT == 'B' & PEN == '15' & SEC >= 0)
dayfile.top <- subset(dayfile, SUN == 'D' & BIOF15 == 'C' & BOT == 'Z' & PEN == '15' & SEC >= 0)
dayfile.out <- subset(dayfile, SUN == 'D' & BIOF15 == 'C' & OUT == '15OE' & PEN == '15' & SEC >= 0| SUN == 'D' & BIOF15 == 'C' & OUT == '15OS' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'C' & OUT == '15ON' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'C' & OUT == '15OW' & PEN == '15' & SEC >= 0)
dayfile.edg <- subset(dayfile, SUN == 'D' & BIOF15 == 'C' & EDG == '15EN' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'C' & EDG == '15EW' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'C' & EDG == '15ES' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'C' & EDG == '15EE' & PEN == '15' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SUN == 'D' & BIOF15 == 'C' & BIGC == '15CNW' & PEN == '15' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SUN == 'D' & BIOF15 == 'C' & BIGC == '15CNE' & PEN == '15' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SUN == 'D' & BIOF15 == 'C' & BIGC == '15CSW' & PEN == '15' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SUN == 'D' & BIOF15 == 'C' & BIGC == '15CSE' & PEN == '15' & SEC >= 0)
dayfile.cen <- subset(dayfile, SUN == 'D' & BIOF15 == 'C' & CEN == '15MH' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'C' & CEN == '15MM' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'C' & CEN == '15ML' & PEN == '15' & SEC >= 0)
dayfile.hid <- subset(dayfile, SUN == 'D' & BIOF15 == 'C' & HID == 'P15HW' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'C' & HID == 'P15HE' & PEN == '15' & SEC >= 0)
dayfile.fs <- subset(dayfile, SUN == 'D' & BIOF15 == 'C' & FS == 'FS15' & PEN == '15' & SEC >= 0)
locations.P15[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
}
location.sum <- rbind(locations.P12, locations.P14, locations.P15)
location.sum$ID <- NULL
location.sum
#loadWorkbook('LocationsOutput.xlsx', create = TRUE)
#writeWorksheetToFile('LocationsOutput.xlsx', location.sum, 'Sheet 1')
write.xlsx(location.sum, 'LocationsOutputNetSwingdayCOnly.xlsx')
}
#------ 2b. Batch location summary for multiple day files Before Net Swings: Cx2 ------
batch.locationsnetswingdayCx2 <- function()
{
files <- list.files(path = workingdir, pattern = '*.csv', all.files = FALSE, recursive = FALSE)
locations.P12 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P12) <- 'ID'
rownames(locations.P12) <- c('P12_<15m', 'P12_>15m', 'P12_outer', 'P12_edge', 'P12_NWcorner', 'P12_NEcorner', 'P12_SWcorner', 'P12_SEcorner', 'P12_centre', 'P12_hides', 'P12_feedstation')
locations.P14 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P14) <- 'ID'
rownames(locations.P14) <- c('P14_<15m', 'P14_>15m', 'P14_outer', 'P14_edge', 'P14_NWcorner', 'P14_NEcorner', 'P14_SWcorner', 'P14_SEcorner', 'P14_centre', 'P14_hides', 'P14_feedstation')
locations.P15 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P15) <- 'ID'
rownames(locations.P15) <- c('P15_<15m', 'P15_>15m', 'P15_outer', 'P15_edge', 'P15_NWcorner', 'P15_NEcorner', 'P15_SWcorner', 'P15_SEcorner', 'P15_centre', 'P15_hides', 'P15_feedstation')
for (i in 1:length(files))
{
dayfile.loc <- files[[i]]
dayfile <- read.csv(dayfile.loc, header = TRUE, sep = ",", colClasses = dayfile.classes)
#SORT BY TIME AND TAG
dayfile <- dayfile[order(dayfile$EchoTime, na.last = FALSE, decreasing = FALSE, method = c("shell")),] # sort by time
dayfile <- dayfile[order(dayfile$Period, na.last = FALSE, decreasing = FALSE, method = c("shell")),] # sort by tag
# pen 12 location summary
dayfile.bot <- subset(dayfile, SUN == 'D' & BIOF12 == 'CC' & BOT == 'B' & PEN == '12' & SEC >= 0)
dayfile.top <- subset(dayfile, SUN == 'D' & BIOF12 == 'CC' & BOT == 'Z' & PEN == '12' & SEC >= 0)
dayfile.out <- subset(dayfile, SUN == 'D' & BIOF12 == 'CC' & OUT == '12OE' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'CC' & OUT == '12OS' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'CC' & OUT == '12ON' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'CC' & OUT == '12OW' & PEN == '12' & SEC >= 0)
dayfile.edg <- subset(dayfile, SUN == 'D' & BIOF12 == 'CC' & EDG == '12EN' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'CC' & EDG == '12EW' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'CC' & EDG == '12ES' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'CC' & EDG == '12EE' & PEN == '12' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SUN == 'D' & BIOF12 == 'CC' & BIGC == '12CNW' & PEN == '12' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SUN == 'D' & BIOF12 == 'CC' & BIGC == '12CNE' & PEN == '12' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SUN == 'D' & BIOF12 == 'CC' & BIGC == '12CSW' & PEN == '12' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SUN == 'D' & BIOF12 == 'CC' & BIGC == '12CSE' & PEN == '12' & SEC >= 0)
dayfile.cen <- subset(dayfile, SUN == 'D' & BIOF12 == 'CC' & CEN == '12MH' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'CC' & CEN == '12MM' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'CC' & CEN == '12ML' & PEN == '12' & SEC >= 0)
dayfile.hid <- subset(dayfile, SUN == 'D' & BIOF12 == 'CC' & HID == 'P12HW' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'CC' & HID == 'P12HE' & PEN == '12' & SEC >= 0)
dayfile.fs <- subset(dayfile, SUN == 'D' & BIOF12 == 'CC' & FS == 'FS12' & PEN == '12' & SEC >= 0)
locations.P12[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
# pen 14 location summary
dayfile.bot <- subset(dayfile, SUN == 'D' & BIOF14 == 'CC' & BOT == 'B' & PEN == '14' & SEC >= 0)
dayfile.top <- subset(dayfile, SUN == 'D' & BIOF14 == 'CC' & BOT == 'Z' & PEN == '14' & SEC >= 0)
dayfile.out <- subset(dayfile, SUN == 'D' & BIOF14 == 'CC' & OUT == '14OE' & PEN == '14' & SEC >= 0| SUN == 'D' & BIOF14 == 'CC' & OUT == '14OS' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'CC' & OUT == '14ON' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'CC' & OUT == '14OW' & PEN == '14' & SEC >= 0)
dayfile.edg <- subset(dayfile, SUN == 'D' & BIOF14 == 'CC' & EDG == '14EN' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'CC' & EDG == '14EW' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'CC' & EDG == '14ES' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'CC' & EDG == '14EE' & PEN == '14' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SUN == 'D' & BIOF14 == 'CC' & BIGC == '14CNW' & PEN == '14' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SUN == 'D' & BIOF14 == 'CC' & BIGC == '14CNE' & PEN == '14' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SUN == 'D' & BIOF14 == 'CC' & BIGC == '14CSW' & PEN == '14' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SUN == 'D' & BIOF14 == 'CC' & BIGC == '14CSE' & PEN == '14' & SEC >= 0)
dayfile.cen <- subset(dayfile, SUN == 'D' & BIOF14 == 'CC' & CEN == '14MH' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'CC' & CEN == '14MM' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'CC' & CEN == '14ML' & PEN == '14' & SEC >= 0)
dayfile.hid <- subset(dayfile, SUN == 'D' & BIOF14 == 'CC' & HID == 'P14HW' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'CC' & HID == 'P14HE' & PEN == '14' & SEC >= 0)
dayfile.fs <- subset(dayfile, SUN == 'D' & BIOF14 == 'CC' & FS == 'FS14' & PEN == '14' & SEC >= 0)
locations.P14[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
# pen 15 location summary
dayfile.bot <- subset(dayfile, SUN == 'D' & BIOF15 == 'CC' & BOT == 'B' & PEN == '15' & SEC >= 0)
dayfile.top <- subset(dayfile, SUN == 'D' & BIOF15 == 'CC' & BOT == 'Z' & PEN == '15' & SEC >= 0)
dayfile.out <- subset(dayfile, SUN == 'D' & BIOF15 == 'CC' & OUT == '15OE' & PEN == '15' & SEC >= 0| SUN == 'D' & BIOF15 == 'CC' & OUT == '15OS' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'CC' & OUT == '15ON' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'CC' & OUT == '15OW' & PEN == '15' & SEC >= 0)
dayfile.edg <- subset(dayfile, SUN == 'D' & BIOF15 == 'CC' & EDG == '15EN' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'CC' & EDG == '15EW' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'CC' & EDG == '15ES' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'CC' & EDG == '15EE' & PEN == '15' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SUN == 'D' & BIOF15 == 'CC' & BIGC == '15CNW' & PEN == '15' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SUN == 'D' & BIOF15 == 'CC' & BIGC == '15CNE' & PEN == '15' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SUN == 'D' & BIOF15 == 'CC' & BIGC == '15CSW' & PEN == '15' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SUN == 'D' & BIOF15 == 'CC' & BIGC == '15CSE' & PEN == '15' & SEC >= 0)
dayfile.cen <- subset(dayfile, SUN == 'D' & BIOF15 == 'CC' & CEN == '15MH' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'CC' & CEN == '15MM' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'CC' & CEN == '15ML' & PEN == '15' & SEC >= 0)
dayfile.hid <- subset(dayfile, SUN == 'D' & BIOF15 == 'CC' & HID == 'P15HW' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'CC' & HID == 'P15HE' & PEN == '15' & SEC >= 0)
dayfile.fs <- subset(dayfile, SUN == 'D' & BIOF15 == 'CC' & FS == 'FS15' & PEN == '15' & SEC >= 0)
locations.P15[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
}
location.sum <- rbind(locations.P12, locations.P14, locations.P15)
location.sum$ID <- NULL
location.sum
#loadWorkbook('LocationsOutput.xlsx', create = TRUE)
#writeWorksheetToFile('LocationsOutput.xlsx', location.sum, 'Sheet 1')
write.xlsx(location.sum, 'LocationsOutputNetSwingdayCx2Only.xlsx')
}
#------ 2b. Batch location summary for multiple day files Before Net Swings: Cx3 ------
batch.locationsnetswingdayCx3 <- function()
{
files <- list.files(path = workingdir, pattern = '*.csv', all.files = FALSE, recursive = FALSE)
locations.P12 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P12) <- 'ID'
rownames(locations.P12) <- c('P12_<15m', 'P12_>15m', 'P12_outer', 'P12_edge', 'P12_NWcorner', 'P12_NEcorner', 'P12_SWcorner', 'P12_SEcorner', 'P12_centre', 'P12_hides', 'P12_feedstation')
locations.P14 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P14) <- 'ID'
rownames(locations.P14) <- c('P14_<15m', 'P14_>15m', 'P14_outer', 'P14_edge', 'P14_NWcorner', 'P14_NEcorner', 'P14_SWcorner', 'P14_SEcorner', 'P14_centre', 'P14_hides', 'P14_feedstation')
locations.P15 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P15) <- 'ID'
rownames(locations.P15) <- c('P15_<15m', 'P15_>15m', 'P15_outer', 'P15_edge', 'P15_NWcorner', 'P15_NEcorner', 'P15_SWcorner', 'P15_SEcorner', 'P15_centre', 'P15_hides', 'P15_feedstation')
for (i in 1:length(files))
{
dayfile.loc <- files[[i]]
dayfile <- read.csv(dayfile.loc, header = TRUE, sep = ",", colClasses = dayfile.classes)
#SORT BY TIME AND TAG
dayfile <- dayfile[order(dayfile$EchoTime, na.last = FALSE, decreasing = FALSE, method = c("shell")),] # sort by time
dayfile <- dayfile[order(dayfile$Period, na.last = FALSE, decreasing = FALSE, method = c("shell")),] # sort by tag
# pen 12 location summary
dayfile.bot <- subset(dayfile, SUN == 'D' & BIOF12 == 'CCC' & BOT == 'B' & PEN == '12' & SEC >= 0)
dayfile.top <- subset(dayfile, SUN == 'D' & BIOF12 == 'CCC' & BOT == 'Z' & PEN == '12' & SEC >= 0)
dayfile.out <- subset(dayfile, SUN == 'D' & BIOF12 == 'CCC' & OUT == '12OE' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'CCC' & OUT == '12OS' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'CCC' & OUT == '12ON' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'CCC' & OUT == '12OW' & PEN == '12' & SEC >= 0)
dayfile.edg <- subset(dayfile, SUN == 'D' & BIOF12 == 'CCC' & EDG == '12EN' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'CCC' & EDG == '12EW' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'CCC' & EDG == '12ES' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'CCC' & EDG == '12EE' & PEN == '12' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SUN == 'D' & BIOF12 == 'CCC' & BIGC == '12CNW' & PEN == '12' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SUN == 'D' & BIOF12 == 'CCC' & BIGC == '12CNE' & PEN == '12' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SUN == 'D' & BIOF12 == 'CCC' & BIGC == '12CSW' & PEN == '12' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SUN == 'D' & BIOF12 == 'CCC' & BIGC == '12CSE' & PEN == '12' & SEC >= 0)
dayfile.cen <- subset(dayfile, SUN == 'D' & BIOF12 == 'CCC' & CEN == '12MH' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'CCC' & CEN == '12MM' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'CCC' & CEN == '12ML' & PEN == '12' & SEC >= 0)
dayfile.hid <- subset(dayfile, SUN == 'D' & BIOF12 == 'CCC' & HID == 'P12HW' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'CCC' & HID == 'P12HE' & PEN == '12' & SEC >= 0)
dayfile.fs <- subset(dayfile, SUN == 'D' & BIOF12 == 'CCC' & FS == 'FS12' & PEN == '12' & SEC >= 0)
locations.P12[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
# pen 14 location summary
dayfile.bot <- subset(dayfile, SUN == 'D' & BIOF14 == 'CCC' & BOT == 'B' & PEN == '14' & SEC >= 0)
dayfile.top <- subset(dayfile, SUN == 'D' & BIOF14 == 'CCC' & BOT == 'Z' & PEN == '14' & SEC >= 0)
dayfile.out <- subset(dayfile, SUN == 'D' & BIOF14 == 'CCC' & OUT == '14OE' & PEN == '14' & SEC >= 0| SUN == 'D' & BIOF14 == 'CCC' & OUT == '14OS' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'CCC' & OUT == '14ON' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'CCC' & OUT == '14OW' & PEN == '14' & SEC >= 0)
dayfile.edg <- subset(dayfile, SUN == 'D' & BIOF14 == 'CCC' & EDG == '14EN' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'CCC' & EDG == '14EW' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'CCC' & EDG == '14ES' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'CCC' & EDG == '14EE' & PEN == '14' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SUN == 'D' & BIOF14 == 'CCC' & BIGC == '14CNW' & PEN == '14' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SUN == 'D' & BIOF14 == 'CCC' & BIGC == '14CNE' & PEN == '14' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SUN == 'D' & BIOF14 == 'CCC' & BIGC == '14CSW' & PEN == '14' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SUN == 'D' & BIOF14 == 'CCC' & BIGC == '14CSE' & PEN == '14' & SEC >= 0)
dayfile.cen <- subset(dayfile, SUN == 'D' & BIOF14 == 'CCC' & CEN == '14MH' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'CCC' & CEN == '14MM' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'CCC' & CEN == '14ML' & PEN == '14' & SEC >= 0)
dayfile.hid <- subset(dayfile, SUN == 'D' & BIOF14 == 'CCC' & HID == 'P14HW' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'CCC' & HID == 'P14HE' & PEN == '14' & SEC >= 0)
dayfile.fs <- subset(dayfile, SUN == 'D' & BIOF14 == 'CCC' & FS == 'FS14' & PEN == '14' & SEC >= 0)
locations.P14[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
# pen 15 location summary
dayfile.bot <- subset(dayfile, SUN == 'D' & BIOF15 == 'CCC' & BOT == 'B' & PEN == '15' & SEC >= 0)
dayfile.top <- subset(dayfile, SUN == 'D' & BIOF15 == 'CCC' & BOT == 'Z' & PEN == '15' & SEC >= 0)
dayfile.out <- subset(dayfile, SUN == 'D' & BIOF15 == 'CCC' & OUT == '15OE' & PEN == '15' & SEC >= 0| SUN == 'D' & BIOF15 == 'CCC' & OUT == '15OS' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'CCC' & OUT == '15ON' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'CCC' & OUT == '15OW' & PEN == '15' & SEC >= 0)
dayfile.edg <- subset(dayfile, SUN == 'D' & BIOF15 == 'CCC' & EDG == '15EN' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'CCC' & EDG == '15EW' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'CCC' & EDG == '15ES' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'CCC' & EDG == '15EE' & PEN == '15' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SUN == 'D' & BIOF15 == 'CCC' & BIGC == '15CNW' & PEN == '15' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SUN == 'D' & BIOF15 == 'CCC' & BIGC == '15CNE' & PEN == '15' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SUN == 'D' & BIOF15 == 'CCC' & BIGC == '15CSW' & PEN == '15' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SUN == 'D' & BIOF15 == 'CCC' & BIGC == '15CSE' & PEN == '15' & SEC >= 0)
dayfile.cen <- subset(dayfile, SUN == 'D' & BIOF15 == 'CCC' & CEN == '15MH' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'CCC' & CEN == '15MM' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'CCC' & CEN == '15ML' & PEN == '15' & SEC >= 0)
dayfile.hid <- subset(dayfile, SUN == 'D' & BIOF15 == 'CCC' & HID == 'P15HW' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'CCC' & HID == 'P15HE' & PEN == '15' & SEC >= 0)
dayfile.fs <- subset(dayfile, SUN == 'D' & BIOF15 == 'CCC' & FS == 'FS15' & PEN == '15' & SEC >= 0)
locations.P15[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
}
location.sum <- rbind(locations.P12, locations.P14, locations.P15)
location.sum$ID <- NULL
location.sum
#loadWorkbook('LocationsOutput.xlsx', create = TRUE)
#writeWorksheetToFile('LocationsOutput.xlsx', location.sum, 'Sheet 1')
write.xlsx(location.sum, 'LocationsOutputNetSwingdayCx3Only.xlsx')
}
#------ 2b. Batch location summary for multiple day files After Net Swings: D ------
batch.locationsnetswingdayD <- function()
{
files <- list.files(path = workingdir, pattern = '*.csv', all.files = FALSE, recursive = FALSE)
locations.P12 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P12) <- 'ID'
rownames(locations.P12) <- c('P12_<15m', 'P12_>15m', 'P12_outer', 'P12_edge', 'P12_NWcorner', 'P12_NEcorner', 'P12_SWcorner', 'P12_SEcorner', 'P12_centre', 'P12_hides', 'P12_feedstation')
locations.P14 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P14) <- 'ID'
rownames(locations.P14) <- c('P14_<15m', 'P14_>15m', 'P14_outer', 'P14_edge', 'P14_NWcorner', 'P14_NEcorner', 'P14_SWcorner', 'P14_SEcorner', 'P14_centre', 'P14_hides', 'P14_feedstation')
locations.P15 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P15) <- 'ID'
rownames(locations.P15) <- c('P15_<15m', 'P15_>15m', 'P15_outer', 'P15_edge', 'P15_NWcorner', 'P15_NEcorner', 'P15_SWcorner', 'P15_SEcorner', 'P15_centre', 'P15_hides', 'P15_feedstation')
for (i in 1:length(files))
{
dayfile.loc <- files[[i]]
dayfile <- read.csv(dayfile.loc, header = TRUE, sep = ",", colClasses = dayfile.classes)
#SORT BY TIME AND TAG
dayfile <- dayfile[order(dayfile$EchoTime, na.last = FALSE, decreasing = FALSE, method = c("shell")),] # sort by time
dayfile <- dayfile[order(dayfile$Period, na.last = FALSE, decreasing = FALSE, method = c("shell")),] # sort by tag
# pen 12 location summary
dayfile.bot <- subset(dayfile, SUN == 'D' & BIOF12 == 'D' & BOT == 'B' & PEN == '12' & SEC >= 0)
dayfile.top <- subset(dayfile, SUN == 'D' & BIOF12 == 'D' & BOT == 'Z' & PEN == '12' & SEC >= 0)
dayfile.out <- subset(dayfile, SUN == 'D' & BIOF12 == 'D' & OUT == '12OE' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'D' & OUT == '12OS' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'D' & OUT == '12ON' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'D' & OUT == '12OW' & PEN == '12' & SEC >= 0)
dayfile.edg <- subset(dayfile, SUN == 'D' & BIOF12 == 'D' & EDG == '12EN' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'D' & EDG == '12EW' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'D' & EDG == '12ES' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'D' & EDG == '12EE' & PEN == '12' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SUN == 'D' & BIOF12 == 'D' & BIGC == '12CNW' & PEN == '12' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SUN == 'D' & BIOF12 == 'D' & BIGC == '12CNE' & PEN == '12' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SUN == 'D' & BIOF12 == 'D' & BIGC == '12CSW' & PEN == '12' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SUN == 'D' & BIOF12 == 'D' & BIGC == '12CSE' & PEN == '12' & SEC >= 0)
dayfile.cen <- subset(dayfile, SUN == 'D' & BIOF12 == 'D' & CEN == '12MH' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'D' & CEN == '12MM' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'D' & CEN == '12ML' & PEN == '12' & SEC >= 0)
dayfile.hid <- subset(dayfile, SUN == 'D' & BIOF12 == 'D' & HID == 'P12HW' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'D' & HID == 'P12HE' & PEN == '12' & SEC >= 0)
dayfile.fs <- subset(dayfile, SUN == 'D' & BIOF12 == 'D' & FS == 'FS12' & PEN == '12' & SEC >= 0)
locations.P12[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
# pen 14 location summary
dayfile.bot <- subset(dayfile, SUN == 'D' & BIOF14 == 'D' & BOT == 'B' & PEN == '14' & SEC >= 0)
dayfile.top <- subset(dayfile, SUN == 'D' & BIOF14 == 'D' & BOT == 'Z' & PEN == '14' & SEC >= 0)
dayfile.out <- subset(dayfile, SUN == 'D' & BIOF14 == 'D' & OUT == '14OE' & PEN == '14' & SEC >= 0| SUN == 'D' & BIOF14 == 'D' & OUT == '14OS' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'D' & OUT == '14ON' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'D' & OUT == '14OW' & PEN == '14' & SEC >= 0)
dayfile.edg <- subset(dayfile, SUN == 'D' & BIOF14 == 'D' & EDG == '14EN' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'D' & EDG == '14EW' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'D' & EDG == '14ES' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'D' & EDG == '14EE' & PEN == '14' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SUN == 'D' & BIOF14 == 'D' & BIGC == '14CNW' & PEN == '14' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SUN == 'D' & BIOF14 == 'D' & BIGC == '14CNE' & PEN == '14' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SUN == 'D' & BIOF14 == 'D' & BIGC == '14CSW' & PEN == '14' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SUN == 'D' & BIOF14 == 'D' & BIGC == '14CSE' & PEN == '14' & SEC >= 0)
dayfile.cen <- subset(dayfile, SUN == 'D' & BIOF14 == 'D' & CEN == '14MH' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'D' & CEN == '14MM' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'D' & CEN == '14ML' & PEN == '14' & SEC >= 0)
dayfile.hid <- subset(dayfile, SUN == 'D' & BIOF14 == 'D' & HID == 'P14HW' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'D' & HID == 'P14HE' & PEN == '14' & SEC >= 0)
dayfile.fs <- subset(dayfile, SUN == 'D' & BIOF14 == 'D' & FS == 'FS14' & PEN == '14' & SEC >= 0)
locations.P14[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
# pen 15 location summary
dayfile.bot <- subset(dayfile, SUN == 'D' & BIOF15 == 'D' & BOT == 'B' & PEN == '15' & SEC >= 0)
dayfile.top <- subset(dayfile, SUN == 'D' & BIOF15 == 'D' & BOT == 'Z' & PEN == '15' & SEC >= 0)
dayfile.out <- subset(dayfile, SUN == 'D' & BIOF15 == 'D' & OUT == '15OE' & PEN == '15' & SEC >= 0| SUN == 'D' & BIOF15 == 'D' & OUT == '15OS' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'D' & OUT == '15ON' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'D' & OUT == '15OW' & PEN == '15' & SEC >= 0)
dayfile.edg <- subset(dayfile, SUN == 'D' & BIOF15 == 'D' & EDG == '15EN' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'D' & EDG == '15EW' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'D' & EDG == '15ES' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'D' & EDG == '15EE' & PEN == '15' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SUN == 'D' & BIOF15 == 'D' & BIGC == '15CNW' & PEN == '15' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SUN == 'D' & BIOF15 == 'D' & BIGC == '15CNE' & PEN == '15' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SUN == 'D' & BIOF15 == 'D' & BIGC == '15CSW' & PEN == '15' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SUN == 'D' & BIOF15 == 'D' & BIGC == '15CSE' & PEN == '15' & SEC >= 0)
dayfile.cen <- subset(dayfile, SUN == 'D' & BIOF15 == 'D' & CEN == '15MH' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'D' & CEN == '15MM' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'D' & CEN == '15ML' & PEN == '15' & SEC >= 0)
dayfile.hid <- subset(dayfile, SUN == 'D' & BIOF15 == 'D' & HID == 'P15HW' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'D' & HID == 'P15HE' & PEN == '15' & SEC >= 0)
dayfile.fs <- subset(dayfile, SUN == 'D' & BIOF15 == 'D' & FS == 'FS15' & PEN == '15' & SEC >= 0)
locations.P15[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
}
location.sum <- rbind(locations.P12, locations.P14, locations.P15)
location.sum$ID <- NULL
location.sum
#loadWorkbook('LocationsOutput.xlsx', create = TRUE)
#writeWorksheetToFile('LocationsOutput.xlsx', location.sum, 'Sheet 1')
write.xlsx(location.sum, 'LocationsOutputNetSwingdayDOnly.xlsx')
}
#------ 2b. Batch location summary for multiple day files Before Net Swings: Dx2 ------
batch.locationsnetswingdayDx2 <- function()
{
files <- list.files(path = workingdir, pattern = '*.csv', all.files = FALSE, recursive = FALSE)
locations.P12 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P12) <- 'ID'
rownames(locations.P12) <- c('P12_<15m', 'P12_>15m', 'P12_outer', 'P12_edge', 'P12_NWcorner', 'P12_NEcorner', 'P12_SWcorner', 'P12_SEcorner', 'P12_centre', 'P12_hides', 'P12_feedstation')
locations.P14 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P14) <- 'ID'
rownames(locations.P14) <- c('P14_<15m', 'P14_>15m', 'P14_outer', 'P14_edge', 'P14_NWcorner', 'P14_NEcorner', 'P14_SWcorner', 'P14_SEcorner', 'P14_centre', 'P14_hides', 'P14_feedstation')
locations.P15 <- data.frame(c('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'))
colnames(locations.P15) <- 'ID'
rownames(locations.P15) <- c('P15_<15m', 'P15_>15m', 'P15_outer', 'P15_edge', 'P15_NWcorner', 'P15_NEcorner', 'P15_SWcorner', 'P15_SEcorner', 'P15_centre', 'P15_hides', 'P15_feedstation')
for (i in 1:length(files))
{
dayfile.loc <- files[[i]]
dayfile <- read.csv(dayfile.loc, header = TRUE, sep = ",", colClasses = dayfile.classes)
#SORT BY TIME AND TAG
dayfile <- dayfile[order(dayfile$EchoTime, na.last = FALSE, decreasing = FALSE, method = c("shell")),] # sort by time
dayfile <- dayfile[order(dayfile$Period, na.last = FALSE, decreasing = FALSE, method = c("shell")),] # sort by tag
# pen 12 location summary
dayfile.bot <- subset(dayfile, SUN == 'D' & BIOF12 == 'DD' & BOT == 'B' & PEN == '12' & SEC >= 0)
dayfile.top <- subset(dayfile, SUN == 'D' & BIOF12 == 'DD' & BOT == 'Z' & PEN == '12' & SEC >= 0)
dayfile.out <- subset(dayfile, SUN == 'D' & BIOF12 == 'DD' & OUT == '12OE' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'DD' & OUT == '12OS' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'DD' & OUT == '12ON' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'DD' & OUT == '12OW' & PEN == '12' & SEC >= 0)
dayfile.edg <- subset(dayfile, SUN == 'D' & BIOF12 == 'DD' & EDG == '12EN' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'DD' & EDG == '12EW' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'DD' & EDG == '12ES' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'DD' & EDG == '12EE' & PEN == '12' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SUN == 'D' & BIOF12 == 'DD' & BIGC == '12CNW' & PEN == '12' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SUN == 'D' & BIOF12 == 'DD' & BIGC == '12CNE' & PEN == '12' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SUN == 'D' & BIOF12 == 'DD' & BIGC == '12CSW' & PEN == '12' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SUN == 'D' & BIOF12 == 'DD' & BIGC == '12CSE' & PEN == '12' & SEC >= 0)
dayfile.cen <- subset(dayfile, SUN == 'D' & BIOF12 == 'DD' & CEN == '12MH' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'DD' & CEN == '12MM' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'DD' & CEN == '12ML' & PEN == '12' & SEC >= 0)
dayfile.hid <- subset(dayfile, SUN == 'D' & BIOF12 == 'DD' & HID == 'P12HW' & PEN == '12' & SEC >= 0 | SUN == 'D' & BIOF12 == 'DD' & HID == 'P12HE' & PEN == '12' & SEC >= 0)
dayfile.fs <- subset(dayfile, SUN == 'D' & BIOF12 == 'DD' & FS == 'FS12' & PEN == '12' & SEC >= 0)
locations.P12[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
# pen 14 location summary
dayfile.bot <- subset(dayfile, SUN == 'D' & BIOF14 == 'DD' & BOT == 'B' & PEN == '14' & SEC >= 0)
dayfile.top <- subset(dayfile, SUN == 'D' & BIOF14 == 'DD' & BOT == 'Z' & PEN == '14' & SEC >= 0)
dayfile.out <- subset(dayfile, SUN == 'D' & BIOF14 == 'DD' & OUT == '14OE' & PEN == '14' & SEC >= 0| SUN == 'D' & BIOF14 == 'DD' & OUT == '14OS' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'DD' & OUT == '14ON' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'DD' & OUT == '14OW' & PEN == '14' & SEC >= 0)
dayfile.edg <- subset(dayfile, SUN == 'D' & BIOF14 == 'DD' & EDG == '14EN' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'DD' & EDG == '14EW' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'DD' & EDG == '14ES' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'DD' & EDG == '14EE' & PEN == '14' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SUN == 'D' & BIOF14 == 'DD' & BIGC == '14CNW' & PEN == '14' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SUN == 'D' & BIOF14 == 'DD' & BIGC == '14CNE' & PEN == '14' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SUN == 'D' & BIOF14 == 'DD' & BIGC == '14CSW' & PEN == '14' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SUN == 'D' & BIOF14 == 'DD' & BIGC == '14CSE' & PEN == '14' & SEC >= 0)
dayfile.cen <- subset(dayfile, SUN == 'D' & BIOF14 == 'DD' & CEN == '14MH' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'DD' & CEN == '14MM' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'DD' & CEN == '14ML' & PEN == '14' & SEC >= 0)
dayfile.hid <- subset(dayfile, SUN == 'D' & BIOF14 == 'DD' & HID == 'P14HW' & PEN == '14' & SEC >= 0 | SUN == 'D' & BIOF14 == 'DD' & HID == 'P14HE' & PEN == '14' & SEC >= 0)
dayfile.fs <- subset(dayfile, SUN == 'D' & BIOF14 == 'DD' & FS == 'FS14' & PEN == '14' & SEC >= 0)
locations.P14[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
# pen 15 location summary
dayfile.bot <- subset(dayfile, SUN == 'D' & BIOF15 == 'DD' & BOT == 'B' & PEN == '15' & SEC >= 0)
dayfile.top <- subset(dayfile, SUN == 'D' & BIOF15 == 'DD' & BOT == 'Z' & PEN == '15' & SEC >= 0)
dayfile.out <- subset(dayfile, SUN == 'D' & BIOF15 == 'DD' & OUT == '15OE' & PEN == '15' & SEC >= 0| SUN == 'D' & BIOF15 == 'DD' & OUT == '15OS' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'DD' & OUT == '15ON' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'DD' & OUT == '15OW' & PEN == '15' & SEC >= 0)
dayfile.edg <- subset(dayfile, SUN == 'D' & BIOF15 == 'DD' & EDG == '15EN' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'DD' & EDG == '15EW' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'DD' & EDG == '15ES' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'DD' & EDG == '15EE' & PEN == '15' & SEC >= 0)
dayfile.NWCor <- subset(dayfile, SUN == 'D' & BIOF15 == 'DD' & BIGC == '15CNW' & PEN == '15' & SEC >= 0)
dayfile.NECor <- subset(dayfile, SUN == 'D' & BIOF15 == 'DD' & BIGC == '15CNE' & PEN == '15' & SEC >= 0)
dayfile.SWCor <- subset(dayfile, SUN == 'D' & BIOF15 == 'DD' & BIGC == '15CSW' & PEN == '15' & SEC >= 0)
dayfile.SECor <- subset(dayfile, SUN == 'D' & BIOF15 == 'DD' & BIGC == '15CSE' & PEN == '15' & SEC >= 0)
dayfile.cen <- subset(dayfile, SUN == 'D' & BIOF15 == 'DD' & CEN == '15MH' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'DD' & CEN == '15MM' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'DD' & CEN == '15ML' & PEN == '15' & SEC >= 0)
dayfile.hid <- subset(dayfile, SUN == 'D' & BIOF15 == 'DD' & HID == 'P15HW' & PEN == '15' & SEC >= 0 | SUN == 'D' & BIOF15 == 'DD' & HID == 'P15HE' & PEN == '15' & SEC >= 0)
dayfile.fs <- subset(dayfile, SUN == 'D' & BIOF15 == 'DD' & FS == 'FS15' & PEN == '15' & SEC >= 0)
locations.P15[,as.character(i)] <- c(sum(dayfile.bot$SEC, na.rm = T)/3600, sum(dayfile.top$SEC, na.rm = T)/3600, sum(dayfile.out$SEC, na.rm = T)/3600, sum(dayfile.edg$SEC, na.rm = T)/3600, sum(dayfile.NWCor$SEC, na.rm = T)/3600, sum(dayfile.NECor$SEC, na.rm = T)/3600, sum(dayfile.SWCor$SEC, na.rm = T)/3600, sum(dayfile.SECor$SEC, na.rm = T)/3600, sum(dayfile.cen$SEC, na.rm = T)/3600, sum(dayfile.hid$SEC, na.rm = T)/3600, sum(dayfile.fs$SEC, na.rm = T)/3600)
}
location.sum <- rbind(locations.P12, locations.P14, locations.P15)
location.sum$ID <- NULL
location.sum