% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/base_when.r
\name{base_when}
\alias{base_when}
\title{Defines factors using logical objects}
\usage{
base_when(..., as_factor = TRUE, string_for_na = "")
}
\arguments{
\item{...}{conditions for defining the replacement values, specified as a named list, with each element in \code{'label'=logical_vector} 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_when()} (from 'dplyr'). Unlike \code{case_when()}, \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)

nhanes<-nhanes |>
  transform(
    cholesterol=base_when(
      'Desirable' = (lbxtc<200),
      'Borderline high' = (lbxtc>=200)&(lbxtc<240),
      'High' = (lbxtc>=240)
    )
  )
}
