% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sdg.R
\name{sdg_clean}
\alias{sdg_clean}
\title{Tidy an SDG Data Frame}
\usage{
sdg_clean(df)
}
\arguments{
\item{df}{A data frame returned by \code{\link[=sdg_data]{sdg_data()}}.}
}
\value{
A \link[tibble:tibble]{tibble} with 15 columns: \code{source} (always
\code{"sdg"}), \code{id}, \code{indicator}, \code{location}, \code{iso3}, \code{location_name},
\code{year}, \code{value}, \code{value_num}, \code{low}, \code{high}, \code{series}, \code{dim1}
(\code{NA}), \code{dim2} (\code{NA}), \code{dim3} (\code{NA}). Sorted by \code{location} then
\code{year}. Empty input returns an empty tibble with the same columns
and types.
}
\description{
Selects, renames, and type-casts the most useful columns from an
SDG observation table returned by \code{\link[=sdg_data]{sdg_data()}}, producing a compact
tibble in the \strong{unified DSIR cleaned-indicator schema} — the same
schema produced by \code{\link[=gho_clean]{gho_clean()}}, so the two outputs can be combined
directly with \code{\link[=bind_indicators]{bind_indicators()}}.
}
\details{
The mapping (SDG source → unified column) is:
\itemize{
\item \code{indicator} (list-column, flattened) → \code{id} (e.g. \code{"3.4.1"})
\item \code{seriesDescription}                  → \code{indicator} (human-readable
label; \code{NA} if the API response does not include it)
\item \code{geoAreaCode}                        → \code{location} (UN M49 numeric,
as character); also \code{iso3} via \code{\link[=m49_to_iso3]{m49_to_iso3()}} for WHO Member
States — region / world aggregates and non-Member areas get
\code{iso3 = NA}
\item \code{location_name} is resolved by looking up \code{iso3} against
\code{\link{who_countries}} (so a WHO Member State has the same
\code{location_name} here and in \code{\link[=gho_clean]{gho_clean()}} output), with a
fallback to the SDG API's raw \code{geoAreaName} for non-Member-State
rows (e.g. regional / world aggregates)
\item \code{timePeriodStart}                    → \code{year} (integer)
\item \code{value}                              → \code{value} (character; raw)
and \code{value_num} (numeric; \code{NA} for non-numeric entries like
\code{"<0.1"} or aggregate notes)
\item \code{lowerBound}, \code{upperBound}           → \code{low}, \code{high} (numeric)
\item \code{series}                             → \code{series}
}

Three columns are always present but never populated for SDG
output: \code{dim1}, \code{dim2}, \code{dim3} (GHO-only concepts).
}
\examples{
\donttest{
sdg_data("3.2.1", area = "156", year_from = 2015) |>
  sdg_clean()
}
}
\seealso{
\code{\link[=sdg_data]{sdg_data()}}, \code{\link[=gho_clean]{gho_clean()}}, \code{\link[=bind_indicators]{bind_indicators()}},
\code{\link[=m49_to_iso3]{m49_to_iso3()}}.
}
