Convert a long data frame with one column for proportions, one column for the bin each proportion belongs to, and stratification columns that inform the model what time, sex, fleet, etc. that the data come from.

comps_wide(
  data,
  breaks,
  col_bins = "Age",
  col_proportions = "lf",
  includeplusgroup = TRUE
)

Arguments

data

A data frame with named columns.

breaks

A vector of cut points to be passed to cut.

col_bins

The column name that pertains the bin or group you wish to transform from long to wide, i.e., every unique value in this column will be a new column in the wide format.

col_proportions

The column name that pertains to the proportion data in the data frame. This column will be used as information for each new column in the wide format, i.e., summed across created categories.

includeplusgroup

A logical defining if you want all values larger than the largest break to be included in the last bin. For example, if the largest value in breaks is 15 and you have age-20 fish, then you should use includeplusgroup = TRUE if you want to have data on this 20 year old fish. The default is to include them.

Value

A data frame with initial columns for each stratification present in the data, i.e., all columns not included in col_bins and col_proportions. Followed by one column for each bin present in the data that sums the proportional information for each combination of stratification and bin. This data frame can often be used as is in Stock Synthesis, though the stratification columns may need to be altered such that sample sizes are correct or added if missing from the stratification levels.

Author

Kelli F. Johnson

Examples

temp <- data.frame(
  state = rep(c("WA", "OR"), length.out = 30),
  year = rep(2010:2015, each = 5),
  Age = rep(1:15, 2),
  ap = rlnorm(n = 30)
)
comps <- comps_wide(temp, breaks = 3:8, col_proportions = "ap")
testthat::expect_equal(NCOL(comps), 8)
if (FALSE) { # \dontrun{
print(comps)
} # }