Aggregate the data contained in a dataset or fit based on the discretized boundaries, using a function and a filling value.

spm_aggregate(
  sspm_object,
  boundaries,
  level = "patch",
  type = "data",
  variable,
  fun,
  group_by = "spacetime",
  fill = FALSE,
  apply_to_df = FALSE,
  ...
)

# S4 method for sspm_dataset,missing
spm_aggregate(
  sspm_object,
  boundaries,
  level = "patch",
  type = "data",
  variable,
  fun,
  group_by = "spacetime",
  fill = FALSE,
  apply_to_df = FALSE,
  ...
)

# S4 method for sspm_dataset,sspm_discrete_boundary
spm_aggregate(
  sspm_object,
  boundaries,
  level = "patch",
  type = "data",
  variable,
  fun,
  group_by = "spacetime",
  fill = FALSE,
  apply_to_df = FALSE,
  ...
)

# S4 method for sspm_fit,ANY
spm_aggregate(
  sspm_object,
  boundaries,
  level = "patch",
  type = "data",
  variable,
  fun,
  group_by = "spacetime",
  fill = FALSE,
  apply_to_df = FALSE,
  ...
)

Arguments

sspm_object

[sspm_dataset or sspm_fit] The dataset object.

boundaries

[sspm_discrete_boundary] The boundaries object (optionnal).

level

[character] The aggregation level, "patch" or "boundary".

type

[character] The targeted type of aggregation, one of "data" for base data or "smoothed" for smoothed data.

variable

[character] Variable to aggregate (ignored in case apply_to_df is TRUE).

fun

[function] Function to use to aggregate data.

group_by

[character] One of time, space and spacetime.

fill

[logical OR numeric OR function] Whether to complete the incomplete cases, default to FALSE for no completion.

apply_to_df

[logical] Wether fun applied to the data frame group or to variable, default to FALSE.

...

More arguments passed onto fun

Value

Updated sspm_dataset or sspm_fit.

Examples

if (FALSE) {
spm_aggregate(sspm_object = catch,
              boundaries = spm_boundaries(biomass),
              variable = catch_variable,
              fun = fun, group_by = group_by,
              fill = fill, apply_to_df = apply_to_df,
              na.rm = TRUE, ...)
}