| add_age | R Documentation |
Create or add to the 'age' table in a GeoTox database.
add_age(GT, df, location = "FIPS")
GT |
GeoTox object. |
df |
Data frame with age simulation data. |
location |
Column name(s) in |
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 simulate_age() to generate age
samples for each location.
The location input can be a named vector to specify multiple identifier
columns in df. For example, location = c(FIPS = "FIPS", state = "ST")
would indicate that df contains both FIPS codes and state identifiers for
locations. The state = "ST" part would rename the "ST" column in df to
"state" in the 'location' table.
The same GeoTox object, invisibly.
simulate_age()
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.