array_utils | R Documentation |
Tools to make munging array reports easier
g3_array_agg(
ar,
margins = NULL,
agg = c(
"sum",
"length_mean", "length_sd",
"predator_length_mean", "predator_length_sd" ),
opt_time_split = !("time" %in% margins || "time" %in% ...names()),
opt_length_midlen = FALSE,
... )
g3_array_combine(
arrays,
agg = sum,
init_val = 0 )
g3_array_plot(
ar,
legend = "topright" )
ar |
Input array, e.g. |
arrays |
List of input arrays, can be a nested list as generated by cons in |
margins |
dimension names to include in the final array, e.g. |
agg |
Function or character. Function to use when aggregating, or name of one of the built-in functions |
init_val |
The initial value to use when combining arrays |
opt_time_split |
Boolean, should we split up "time" into separate "year" & "step" dimensions? |
opt_length_midlen |
Boolean, should we convert "length" |
legend |
Location of legend, passed to |
... |
Filters to apply to any dimension, including "year" / "step" if opt_time_split is TRUE. e.g. |
g3_array_agg
allows you to both filter & aggregate an array at the same time.
Specifying a filter in ... is simplfied in comparison to a regular R subset:
You can give the dimensions in any order
Values are always interpreted, age = 3
will be interpreted as "age3"
, not the third age.
For particular dimensions we have extra helpers:
Numeric ages e.g. age = 5
are converted to "age5", as generated by gadget3
Numeric lengths will pick a value within groups, e.g. with lengths "10:20", "20:30", length = 15
will pick the smaller lengthgroup
g3_array_combine
generates the union of 2 disjoint arrays,
so you can combine aggregated output from an immature and mature stock for example.
g3_array_plot
will plot the contents of an array, for arrays with 2 dimensions or less.
An array, filtered by ... and aggregated by margins
# Generate an array to test with
dn <- list(
length = c("50:60", "60:70", "70:Inf"),
age = paste0("age", 0:5),
time = paste0(rep(1990:1996, each = 2), c("-01", "-02")) )
ar <- array(
seq_len(prod(sapply(dn, length))),
dim = sapply(dn, length),
dimnames = dn)
ar[,,"1994-02", drop = FALSE]
g3_array_plot(ar[,,"1994-02"])
g3_array_plot(ar["50:60","age3",])
# Generate by-year report for ages 2..4
g3_array_agg(ar, c('age', 'year'), age = 2:4)
# ...for only step 1
g3_array_agg(ar, c('age', 'year'), age = 2:4, step = 1)
# Report on smallest length group, for each timestep
g3_array_agg(ar, c('length', 'time'), length = 55)
# Use midlen as the dimension name
g3_array_agg(ar, c('length', 'time'), length = 55, opt_length_midlen = TRUE)
# Combine 2 arrays with disjoint age ranges into one list
g3_array_combine(list(
g3_array_agg(ar, c('age', 'year'), age = 2:4),
g3_array_agg(ar / 1000, c('age', 'year'), age = 3:5) ))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.