Rev 27733 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{Comparison}\alias{<}\alias{<=}\alias{==}\alias{!=}\alias{>=}\alias{>}\alias{Comparison}\title{Relational Operators}\description{Binary operators which allow the comparison of values in atomic vectors.}\usage{x < yx > yx <= yx >= yx == yx != y}\arguments{\item{x, y}{atomic vectors, or other objects for which methods havebeen written.}}\details{The binary comparison operators are generic functions: methods can bewritten for them individually or via the \code{\link{Ops}}) group genericfunction.Comparison of strings in character vectors is lexicographic within thestrings using the collating sequence of the locale in use: see\code{\link{locales}}. The collating sequence of locales such as\samp{en\_US} is normally different from \samp{C} (which should useASCII) and can be surprising.}\value{A vector of logicals indicating the result of the element by elementcomparison. The elements of shorter vectors are recycled asnecessary.Objects such as arrays or time-series can be compared this wayprovided they are conformable.}\note{Don't use \code{==} and \code{!=} for tests, such as in \code{if}expressions, where you must get a single \code{TRUE} or\code{FALSE}. Unless you are absolutely sure that nothing unusualcan happen, you should use the \code{\link{identical}} functioninstead.For numerical values, remember \code{==} and \code{!=} do not allowfor the finite representation of fractions, nor for rounding error.Using \code{\link{all.equal}} with \code{identical} is almostalways preferable. See the examples.}\references{Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)\emph{The New S Language}.Wadsworth \& Brooks/Cole.}\seealso{\code{\link{Syntax}} for operator precedence.}\examples{x <- rnorm(20)x < 1x[x > 0]x1 <- 0.5 - 0.3x2 <- 0.3 - 0.1x1 == x2 # FALSE on most machinesidentical(all.equal(x1, x2), TRUE) # TRUE everywhere}\keyword{logic}