-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata-datras.R
100 lines (82 loc) · 1.76 KB
/
data-datras.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
## Preprocess data, write TAF data tables
## Before:
## After:
source("utilities.R")
detachAllPackages()
library(icesTAF)
library(dplyr)
library(tidyr)
library(sf)
mkdir("data")
source("utilities.R")
# load control file and write out summary table:
data_overview <- read.taf("bootstrap/data/control_file/control_file.csv")
# read in datras data
datras <-
read.taf(
"bootstrap/data/datras/datras_data.csv",
colClasses = c("StatRec" = "character")
)
# read in sst data by area
sst <-
read.taf(
"data/sst.csv"
)
# read in statsq table from previous step
statrecs <-
read.taf(
"data/statrecs.csv",
colClasses = c("StatRec" = "character")
)
# read in species info
biogeog <-
read.taf(
"data/biogeog.csv"
)
# join areas onto datras then filter by control file,
# then join sst values and finally
# join this data onto the species affinity data
lusitanian <-
datras %>%
left_join(
statrecs, by = "StatRec"
) %>%
right_join(
data_overview,
by = c("Survey" = "Survey.name", "F_CODE" = "Division", "Quarter" = "Quarter")
) %>%
filter(
Year >= Start.year
) %>%
select(
-Start.year
) %>%
left_join(
sst, by = c("Year", "F_CODE")
) %>%
inner_join(
biogeog, by = c("Valid_Aphia" = "AphiaID")
)
if (FALSE) {
# check on porcupine bank survey
lusitanian %>%
filter(Survey == "SP-PORC") %>%
tibble() %>%
count(Year)
}
if (FALSE) {
lusitanian %>%
filter(Survey == "SP-PORC" & Year == 2015)
datras %>%
filter(Survey == "SP-PORC" & Year == 2015)
# checks
lusitanian %>%
filter(
F_CODE == "4.c"
) %>%
select(
Survey, Year, Quarter, F_CODE
) %>%
unique()
}
write.taf(lusitanian, dir = "data", quote = TRUE)