-
Notifications
You must be signed in to change notification settings - Fork 1
/
report_tables.R
62 lines (51 loc) · 2.12 KB
/
report_tables.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
## Prepare tables for report
## Before: catage.csv, maturity.csv, survey_smh.csv, wcatch.csv,
## wstock.csv (data), fatage.csv, natage.csv, summary.csv (output)
## After: catage.csv, fatage.csv, maturity.csv, natage.csv, survey_smh.csv,
## summary.csv, wcatch.csv, wstock.csv (report)
library(icesTAF)
mkdir("report")
## catage (plus group)
catage <- read.taf("data/catage.csv")
catage$"10" <- rowSums(catage[as.character(10:14)])
catage <- plus(catage[c("Year", as.character(2:10))])
write.taf(catage, dir="report")
## survey_smh (skip year)
survey.smh <- read.taf("data/survey_smh.csv")
survey.smh <- na.omit(survey.smh)
write.taf(survey.smh, dir="report")
## wstock (trim year and age)
wstock <- read.taf("data/wstock.csv")
wstock <- head(wstock, -1)[c("Year",as.character(1:10))]
write.taf(wstock, dir="report")
## wcatch (trim year and age)
wcatch <- read.taf("data/wcatch.csv")
wcatch <- head(wcatch, -2)[c("Year",as.character(2:10))]
write.taf(wcatch, dir="report")
## maturity (trim year and age)
maturity <- read.taf("data/maturity.csv")
maturity <- head(maturity, -1)[c("Year",as.character(2:10))]
write.taf(maturity, dir="report")
## summary (select columns, trim year, insert NA, average, round)
summary <- read.taf("output/summary.csv")
summary$RefB <- summary$HR <- NULL
summary <- head(summary, -4)
summary$Fbar[nrow(summary)] <- NA
avg <- as.data.frame(t(colMeans(head(summary,-1), na.rm=TRUE)))
avg["Year"] <- paste0("Mean79-", summary$Year[nrow(summary)-1])
summary <- rbind(summary, avg)
summary <- rnd(summary, c("Rec","B3plus","SSB","Landings"))
summary <- rnd(summary, c("YoverSSB","Fbar"), 3)
write.taf(summary, dir="report")
## natage (trim year and age, change units, round)
natage <- read.taf("output/natage.csv")
natage <- head(natage, -2)[c("Year", as.character(1:10))]
natage[-1] <- natage[-1] / 1000
natage <- rnd(natage, as.character(1:5), 1)
natage <- rnd(natage, as.character(6:10), 2)
write.taf(natage, dir="report")
## fatage (trim year and age)
fatage <- read.taf("output/fatage.csv")
fatage <- head(fatage, -2)[c("Year", as.character(2:10))]
fatage <- round(fatage, 3)
write.taf(fatage, dir="report")