Rev 24300 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{ifelse}\title{Conditional Element Selection}\usage{ifelse(test, yes, no)}\alias{ifelse}\description{\code{ifelse} returns a value with the same shape as\code{test} which is filled with elements selectedfrom 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.}\arguments{\item{test}{a logical vector}\item{yes}{return values for true elements of \code{test}.}\item{no}{return values for false elements of \code{test}.}}\references{Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)\emph{The New S Language}.Wadsworth \& Brooks/Cole.}\seealso{\code{\link{if}}.}\examples{x <- c(6:-4)sqrt(x)#- gives warningsqrt(ifelse(x >= 0, x, NA))# no warning## Note: the following also gives the warning !ifelse(x >= 0, sqrt(x), NA)}\keyword{logic}\keyword{programming}