\Header{ifelse}{Conditional Element Selection}
\keyword{logic}{ifelse}
\keyword{programming}{ifelse}
\begin{Description}\relax
\code{ifelse} returns a value with the same shape as
\code{test} which is filled with elements selected
from either \code{yes} or \code{no}
depending on whether the element of \code{test}
is \code{TRUE} or \code{FALSE}.
If \code{yes} or \code{no} are too short, their elements are recycled.\end{Description}
\begin{Usage}
\begin{verbatim}
ifelse(test, yes, no)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{test}] a logical vector
\item[\code{yes}] return values for true elements of \code{test}.
\item[\code{no}] return values for false elements of \code{test}.
\end{ldescription}
\end{Arguments}
\begin{References}\relax
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
\emph{The New S Language}.
Wadsworth \& Brooks/Cole.\end{References}
\begin{SeeAlso}\relax
\code{\Link{if}}.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
x <- c(6:-4)
sqrt(x)#- gives warning
sqrt(ifelse(x >= 0, x, NA))# no warning

## Note: the following also gives the warning !
ifelse(x >= 0, sqrt(x), NA)
\end{ExampleCode}
\end{Examples}

