% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/hmetad.R
\name{to_signed}
\alias{to_signed}
\alias{to_unsigned}
\title{Convert binary variable \eqn{x} between \eqn{\{0, 1\}} and \eqn{\{-1, 1\}}}
\usage{
to_signed(x)

to_unsigned(x)
}
\arguments{
\item{x}{A binary variable}
}
\value{
A signed (for \code{to_signed}) or unsigned (for \code{to_unsigned}) version
of \code{x}
}
\description{
\itemize{
\item \code{to_signed(x)} converts \eqn{x \in \{0, 1\}} to \eqn{x' \in \{-1, 1\}}
\item \code{to_unsigned(x)} converts \eqn{x \in \{-1, 1\}} to \eqn{x' \in \{0, 1\}}
}
}
\examples{
# should return `1`
to_signed(0)

# should return `1`
to_signed(1)

# should return `0`
to_unsigned(-1)

# should return `1`
to_unsigned(1)

# `to_signed` also works with objects `R` interprets as `0` or `1`
to_signed(10)

# `to_unsigned` also works with any signed integer
to_unsigned(-10)

# neither function works with factors
try(to_signed(factor(1)))
tryCatch(to_unsigned(factor(1)), warning = function(w) w)
}
