% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/add_tables.R
\name{add_age}
\alias{add_age}
\title{Add age simulation data}
\usage{
add_age(GT, df, location = "FIPS")
}
\arguments{
\item{GT}{GeoTox object.}

\item{df}{Data frame with age simulation data.}

\item{location}{Column name(s) in \code{df} that contain location identifier(s)
(default "FIPS").}
}
\value{
The same GeoTox object, invisibly.
}
\description{
Create or add to the 'age' table in a GeoTox database.
}
\details{
The simulation data must have columns "AGEGRP" and "TOT_POP" and at least one
column containing location information (default "FIPS"). Each location must
have 19 rows for AGEGRP 0-18, where 1-18 are age groups in increments of 5,
e.g. AGEGRP = 5 would be ages 20 to 24, and AGEGRP = 0 is the combination of
all age groups. The age data is used by \code{\link[=simulate_age]{simulate_age()}} to generate age
samples for each location.

The \code{location} input can be a named vector to specify multiple identifier
columns in \code{df}. For example, \code{location = c(FIPS = "FIPS", state = "ST")}
would indicate that \code{df} contains both FIPS codes and state identifiers for
locations. The \code{state = "ST"} part would rename the "ST" column in \code{df} to
"state" in the 'location' table.
}
\examples{
# Example age simulation data
age_df <- data.frame(
  FIPS = rep(c(10000, 20000), each = 19),
  AGEGRP = rep(0:18, times = 2),
  TOT_POP = 0
)
# FIPS 10000, populate age group 40-44
age_df$TOT_POP[c(1, 10)] = 100
# FIPS 20000, populate age groups 50-59
age_df$TOT_POP[c(1, 12, 13) + 19] = c(200, 100, 100)

# Add age simulation data to GeoTox database
GT <- GeoTox() |> add_age(age_df)

# Open a connection to GeoTox database
con <- get_con(GT)

# Look at created tables

dplyr::tbl(con, "age") |> dplyr::filter(TOT_POP > 0) |> dplyr::collect()

dplyr::tbl(con, "location") |> dplyr::collect()

# Clean up example
DBI::dbDisconnect(con)
file.remove(GT$db_info$dbdir)
}
\seealso{
\code{\link[=simulate_age]{simulate_age()}}
}
