% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utility.R
\name{detect_adm2_type}
\alias{detect_adm2_type}
\title{Detect adm2 type from adm2_code field then return the exact codes}
\usage{
detect_adm2_type(df, year = NULL, mode = "non", adm2_code = "adm2_code")
}
\arguments{
\item{df}{A head data frame containing the full dataset.
i.e., \code{censuskor}}

\item{year}{The year for which to filter the data.
If not specified, the function will use the data.frame as is.}

\item{mode}{A character vector of "atn" (autonomous) and
"non" (non-autonomous).}

\item{adm2_code}{A character vector of adm2_code field
Default is "adm2_code".}
}
\value{
filtered data frame with exact codes
}
\description{
adm2_code often refers to the codes of autonomous _Gu_s or
non-autonomous _Gu_s. The head table of the data frame may contain
either or both of the two types of codes. This function detects the type of
the codes in the adm2_code field and returns the exact codes accordingly.
}
\examples{
# Load 2020 census population
pop20 <- anycensus(year = 2020, type = "population")
pop20_nonauto <- detect_adm2_type(pop20, mode = "non")
pop20_auto <- detect_adm2_type(pop20, mode = "atn")
unique(pop20_nonauto$adm2_code)
unique(pop20_auto$adm2_code)
}
