-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMA night dive data analysis.R
105 lines (54 loc) · 3 KB
/
MA night dive data analysis.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
library(psych)
library(pastecs)
library(lubridate)
library(plyr)
library(tidyverse)
library(ggplot2)
library(corrplot)
library(GGally)
library(ggpubr)
library(writexl)
##Import mid_atlantic_night_dive_data.csv with readR and convert diveEnddate and diveStartdate columns to datetime format from pulldown menu
##rename dataframe
night_dive <- mid_atlantic_night_dive_data
head(night_dive)
##convert UTC to EST for start and end dive times
attr(night_dive$diveStartdate, "tzone") <- "America/New_York"
attr(night_dive$diveEnddate, "tzone") <- "America/New_York"
head(night_dive) # check top row to see that time changed
##separate dateTime column into date column and time column (used on diveStartdate AND diveEnddate)
night_dive <- tidyr::separate(night_dive, diveStartdate, c("diveStartdate", "diveStarttime"), sep = " ")
night_dive <- tidyr::separate(night_dive, diveEnddate, c("diveEnddate", "diveEndtime"), sep = " ")
##separating datetime column into two columns makes the date and time columns
##character strings rather than true date and time formats
##convert character string of diveStartdate and diveEnddate to date class
night_dive$diveStartdate <- as.Date(night_dive$diveStartdate)
night_dive$diveEnddate <- as.Date(night_dive$diveEnddate)
##create a dataframe that only includes night data
##R didn't like going from 20 to 06, so had to go from 20 to 23:59, and then 00:00 to 06:00 in 2
##dataframes, then merge the 2 dataframes with r-bind
night <- night_dive %>%
filter(diveStarttime >= ('20:00:00'),
diveStarttime <= ('23:59:59'))
night1 <- night_dive %>%
filter(diveStarttime >= ('00:00:00'),
diveStarttime <= ('06:00:00'))
##bind 2 dataframes
full_night <- rbind(night, night1) ## went from 186,353 records to 80224 records - 43% of all dives from 2010 to 2021 were night dives
##remove night dives shallower than 100ft contour (33m)
NDA33 <- full_night %>%
filter(maxDepth > 33)
##divide surface and dive duration by 3600 to convert from seconds to hours
NDA33$dive_dur <- NDA33$dive_dur / 3600
NDA33$surf_dur <- NDA33$surf_dur / 3600
##export xlsx file to import in to ArcGIS Pro
write_xlsx(NDA33,"C:\\Users\\brian.galvez\\Documents\\Fisheries\\Monkfish Gillnet Study\\Manuscript Data - 2017 & 2021\\tag dive data analysis\\NDA33.xlsx")
##remove night dives shallower than 22m maxDepth (shallowest depth of turtle takes in monkfish fishery from 2010-present))
NDA22 <- full_night %>%
filter(maxDepth > 22) # 5582 records of 186,353 dove deeper than 22 meters - 2.99%
##divide surface and dive duration by 3600 to convert from seconds to hours
NDA22$dive_dur <- NDA22$dive_dur / 3600
NDA22$surf_dur <- NDA22$surf_dur / 3600
head(NDA22)
##export xlsx file to import in to ArcGIS Pro
write_xlsx(NDA22,"C:\\Users\\brian.galvez\\Documents\\Fisheries\\Monkfish Gillnet Study\\Manuscript Data - 2017 & 2021\\Mid Atlantic tag dive data analysis\\NDA22_2022.xlsx")