-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdata.R
62 lines (49 loc) · 2.1 KB
/
data.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
### ------------------------------------------------------------------------ ###
### Preprocess data, write TAF data tables ####
### ------------------------------------------------------------------------ ###
## Before: bootstrap/data/FSP7e.csv
## bootstrap/data/advice/advice_history.csv
## bootstrap/data/InterCatch_length.csv
## After: data/idx.csv
## data/advice_history.csv
## data/length_data.rds
library(TAF)
library(tidyr)
library(dplyr)
### create folder to store data
mkdir("data")
### ------------------------------------------------------------------------ ###
### Biomass index data ####
### ------------------------------------------------------------------------ ###
### 1 biomass index: FSP7e
### - biomass at age (standardised)
### load data from csv
idxB <- read.csv("boot/data/FSP7e.csv")
### only ages 2-8 are used -> sum up biomass
idxB <- cbind(idxB["year"],
index = apply(idxB[, paste0("X", as.character(2:8))], 1, sum))
### save in data directory
write.taf(idxB, file = "data/idx.csv")
saveRDS(idxB, file = "data/idx.rds")
### ------------------------------------------------------------------------ ###
### catch and advice data ####
### ------------------------------------------------------------------------ ###
catch <- read.csv("boot/data/advice_history.csv")
names(catch)[1] <- "year"
write.taf(catch, file = "data/advice_history.csv")
saveRDS(catch, file = "data/advice_history.rds")
### ------------------------------------------------------------------------ ###
### length data ####
### ------------------------------------------------------------------------ ###
### raised data from InterCatch
### load data
lngth_full <- read.csv("boot/data/InterCatch_length.csv")
### summarise data
lngth <- lngth_full %>%
filter(CatchCategory %in% c("Discards", "Landings")) %>%
select(year = Year, catch_category = CatchCategory, length = AgeOrLength,
numbers = CANUM) %>%
group_by(year, catch_category, length) %>%
summarise(numbers = sum(numbers))
write.taf(lngth, file = "data/length_data.csv")
saveRDS(lngth, file = "data/length_data.rds")