Convert a datras_raw / DATRASraw object to either long or wide tabular
format using haul-level (HH) variables only.
Arguments
- x
A
datras_rawobject.- vars
Character vector of
HHvariable names to include. Defaults to 15 common haul-level columns:Survey,Gear,Country,Ship,Year,Quarter,Month,Day,lon,lat,timeOfYear,abstime,DayNight,TimeShotHour,HaulDur.- add_vars
Character vector of additional
HHvariable names to append tovars. Applied afterremove_vars.- remove_vars
Character vector of variable names to drop from
vars. Applied beforeadd_vars.- type
Character string specifying the output format:
"long"(default) or"wide".
Details
This is a convenience wrapper around as_long_format() and
as_wide_format().
Both functions only use columns from the HH table. In addition to
explicitly requested vars, HaulN, HaulWgt, and SweptArea are
always appended when present in HH (e.g. after calling
add_total_numbers_by_haul(), add_total_weight_by_haul(), or
add_swept_area()).
Matrix columns such as HaulN or HaulWgt produced by passing
length_cuts to add_total_numbers_by_haul() or
add_total_weight_by_haul() are handled differently by each format:
type = "long": matrix columns are expanded to one row per haul x length group. ALengthGroupcolumn is added identifying the bin. All matrix columns must share the same bin structure.type = "wide": matrix columns are expanded to one column per length bin, named<variable>_<bin>(e.g.HaulN_(0-20]).
Examples
dab <- add_numbers_at_length(dab)
#> Warning: Mixed accuracies found in var[[3]]$LngtCode - worst chosen: 1 cm
#> Warning: NAs found in var[[3]]$LngtCode - assumed to be 1 cm
dab <- add_total_numbers_by_haul(dab, length_cuts = c(0, 20, Inf))
## Long format - one row per haul x length group
tab_long <- as_table(dab, type = "long")
## Wide format - one column per length group
tab_wide <- as_table(dab, type = "wide")
## Adjust the default column set
tab <- as_table(dab, add_vars = "Depth", remove_vars = "Ship")
