% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/base_match.r
\name{base_match}
\alias{base_match}
\title{Defines factors using value-label mapping}
\usage{
base_match(original_variable, ..., as_factor = TRUE, string_for_na = "")
}
\arguments{
\item{original_variable}{the original variable}

\item{...}{the codebook, specified as a named vector, with each element in \code{'label'=level} format, with the levels listed in the desired order}

\item{as_factor}{logical, controlling whether the function should return a factor}

\item{string_for_na}{string value that will be converted to NA}
}
\value{
a factor
}
\description{
A base-R approximation of \code{case_match()} (from 'dplyr'). Unlike \code{case_match()}, \code{base_when()} returns a factor. The levels will be ordered according to the order included in \code{...} (see below).
}
\examples{
# load data
data(nhanes)

# define country
nhanes<-nhanes |> transform(
  country=base_match(dmdborn4,'USA'=1,'Other'=2)
)
}
