Convert_discardLF_to_ss3_format_Fn: Function to convert length-frequency of expanded discards to...

Usage Arguments Examples

View source: R/Convert_discardLF_to_ss3_format_Fn.R

Usage

1
Convert_discardLF_to_ss3_format_Fn(Length_Frequency_Table, LengthBins, season = 1, fleet = NA, gender = 0, partition = 1)

Arguments

Length_Frequency_Table
LengthBins
season
fleet
gender
partition

Examples

 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
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (Length_Frequency_Table, LengthBins, season = 1, fleet = NA, 
    gender = 0, partition = 1) 
{
    Year_Set = sort(unique(Length_Frequency_Table[, "Year"]))
    RowUsedTF = rep(FALSE, nrow(Length_Frequency_Table))
    Matrix = matrix(0, nrow = length(Year_Set), ncol = 6 + 2 * 
        length(LengthBins), dimnames = list(NULL, c("Year", "Season", 
        "Fleet", "Gender", "Partition", "Nsamp", paste0("F_", 
            LengthBins), paste0("M_", LengthBins))))
    Return = data.frame(Matrix)
    for (yI in 1:length(Year_Set)) {
        Return[yI, c("Year", "Season", "Fleet", "Gender", "Partition")] = c(Year_Set[yI], 
            season, fleet, gender, partition)
        for (lI in 1:length(LengthBins)) {
            RowNum = which(Length_Frequency_Table[, "Year"] == 
                Year_Set[yI] & Length_Frequency_Table[, "Lenbin"] == 
                LengthBins[lI])
            if (length(RowNum) >= 2) 
                stop("Check Length_Frequency_Table for duplicated rows")
            if (length(RowNum) == 1) {
                Return[yI, paste0("F_", LengthBins[lI])] = Length_Frequency_Table[RowNum, 
                  "Prop.numbers"]
                RowUsedTF[RowNum] = TRUE
            }
        }
    }
    if (any(RowUsedTF == FALSE)) {
        stop(paste("Rows", which(RowUsedTF == FALSE), "not used"))
    }
    if (sum(Return[, paste0("F_", LengthBins)]) != sum(Length_Frequency_Table[, 
        "Prop.numbers"])) {
        stop("totals don't match")
    }
    return(Return)
  }

nwfsc-assess/nwfscDiscards documentation built on May 23, 2017, 6:03 p.m.