% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/aggregate_gsas.r
\name{aggregate_gsas}
\alias{aggregate_gsas}
\title{Aggregate MEDITS data across multiple GSAs}
\usage{
aggregate_gsas(
  ta,
  tb,
  tc,
  gsas,
  strata_scheme = BioIndex::strata_scheme,
  stratification = BioIndex::stratification
)
}
\arguments{
\item{ta}{A data frame containing the MEDITS \code{TA} table.}

\item{tb}{A data frame containing the MEDITS \code{TB} table.}

\item{tc}{A data frame containing the MEDITS \code{TC} table.}

\item{gsas}{A numeric or character vector of GSA codes to be aggregated.}

\item{strata_scheme}{A data frame describing the depth-strata scheme for the
selected GSAs. Defaults to \code{BioIndex::strata_scheme}.}

\item{stratification}{A data frame containing the stratification information
for the selected GSAs. Defaults to \code{BioIndex::stratification}.}
}
\value{
A list with five elements:
\describe{
  \item{[[1]]}{The filtered and aggregated \code{TA} table.}
  \item{[[2]]}{The filtered and aggregated \code{TB} table.}
  \item{[[3]]}{The filtered and aggregated \code{TC} table.}
  \item{[[4]]}{The filtered and updated \code{stratification} table.}
  \item{[[5]]}{The filtered and updated \code{strata_scheme} table.}
}
}
\description{
Aggregate TA, TB, and TC MEDITS tables across a user-defined set of
Geographical Sub-Areas (GSAs), and update the associated stratification
objects accordingly.
}
\details{
This function filters the input TA, TB, and TC tables to retain only the
selected GSAs, concatenates the original \code{AREA} and \code{HAUL_NUMBER}
values to create unique haul identifiers across GSAs, and replaces the
\code{AREA} field with a single aggregated GSA code obtained by collapsing
the selected GSA values into one string. The same aggregation is applied to
the \code{stratification} and \code{strata_scheme} tables.


The function performs three main operations:
\enumerate{
  \item Checks that all requested GSAs are present in the \code{AREA} column
  of the input \code{ta}, \code{tb}, and \code{tc} tables.
  \item Filters the three MEDITS tables to the selected GSAs and updates
  \code{HAUL_NUMBER} by prefixing it with the original \code{AREA} value,
  ensuring uniqueness after aggregation.
  \item Filters and updates the \code{stratification} and
  \code{strata_scheme} tables so that all selected GSAs are represented under
  a single aggregated GSA code.
}

The aggregated GSA code is created using \code{paste(gsas, collapse = "")}.
For example, \code{c(17, 18)} becomes \code{"1718"}.
}
\examples{
# Use internal data
data("strata_scheme", package = "BioIndex")
data("stratification", package = "BioIndex")
data("TA", package = "BioIndex")
data("TB", package = "BioIndex")
data("TC", package = "BioIndex")

d <- aggregate_gsas(
  ta = TA,
  tb = TB,
  tc = TC,
  gsas = 10,
  strata_scheme = BioIndex::strata_scheme,
  stratification = BioIndex::stratification
)

ta_agg <- d[[1]]
tb_agg <- d[[2]]
tc_agg <- d[[3]]
stratification_agg <- d[[4]]
strata_scheme_agg <- d[[5]]

}
\seealso{
\code{\link[BioIndex:BioIndex]{strata_scheme}},
\code{\link[BioIndex:BioIndex]{stratification}}
}
