% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/to_dummy.R
\name{to_dummy}
\alias{to_dummy}
\title{Split (categorical) vectors into dummy variables}
\usage{
to_dummy(x, ..., var.name = "name", suffix = c("numeric", "label"))
}
\arguments{
\item{x}{A vector or data frame.}

\item{...}{Optional, unquoted names of variables that should be selected for
further processing. Required, if \code{x} is a data frame (and no
vector) and only selected variables from \code{x} should be processed.
You may also use functions like \code{:} or tidyselect's
select-helpers.
See 'Examples' or \href{../doc/design_philosophy.html}{package-vignette}.}

\item{var.name}{Indicates how the new dummy variables are named. Use
\code{"name"} to use the variable name or any other string that will
be used as is. Only applies, if \code{x} is a vector. See 'Examples'.}

\item{suffix}{Indicates which suffix will be added to each dummy variable.
Use \code{"numeric"} to number dummy variables, e.g. \emph{x_1},
\emph{x_2}, \emph{x_3} etc. Use \code{"label"} to add value label,
e.g. \emph{x_low}, \emph{x_mid}, \emph{x_high}. May be abbreviated.}
}
\value{
A data frame with dummy variables for each category of \code{x}.
        The dummy coded variables are of type \code{\link{atomic}}.
}
\description{
This function splits categorical or numeric vectors with
               more than two categories into 0/1-coded dummy variables.
}
\note{
\code{NA} values will be copied from \code{x}, so each dummy variable
        has the same amount of \code{NA}'s at the same position as \code{x}.
}
\examples{
data(efc)
head(to_dummy(efc$e42dep))

# add value label as suffix to new variable name
head(to_dummy(efc$e42dep, suffix = "label"))

# use "dummy" as new variable name
head(to_dummy(efc$e42dep, var.name = "dummy"))

# create multiple dummies, append to data frame
to_dummy(efc, c172code, e42dep)

# pipe-workflow
library(dplyr)
efc \%>\%
  select(e42dep, e16sex, c172code) \%>\%
  to_dummy()

}
