\HeaderA{Comparison}{Relational Operators}{Comparison}
\aliasA{"!=}{Comparison}{"!=}
\aliasA{<}{Comparison}{<}
\aliasA{<=}{Comparison}{<=}
\aliasA{==}{Comparison}{==}
\aliasA{>}{Comparison}{>}
\aliasA{>=}{Comparison}{>=}
\keyword{logic}{Comparison}
\begin{Description}\relax
Binary operators which allow the comparison of values in atomic vectors.
\end{Description}
\begin{Usage}
\begin{verbatim}
x < y
x > y
x <= y
x >= y
x == y
x != y
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x, y}] atomic vectors, symbols, calls, or other objects for which
methods have been written.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The binary comparison operators are generic functions: methods can be
written for them individually or via the
\code{\LinkA{Ops}{Ops}}) group generic function.  (See
\code{\LinkA{Ops}{Ops}} for how dispatch is computed.)

Comparison of strings in character vectors is lexicographic within the
strings using the collating sequence of the locale in use: see
\code{\LinkA{locales}{locales}}.  The collating sequence of locales such as
\samp{en\_US} is normally different from \samp{C} (which should use
ASCII) and can be surprising.

At least one of \code{x} and \code{y} must be an atomic vector, but if
the other is a list \R{} attempts to coerce it to the type of the atomic
vector: this will succeed if the list is made up of elements of length
one that can be coerced to the correct type.

If the two arguments are atomic vectors of different types, one is
coerced to the type of the other, the (decreasing) order of precedence
being character, complex, numeric, integer, logical and raw.

When comparisons are made between character strings, parts of the
strings after embedded \code{nul} characters are ignored.  (This is
necessary as the position of \code{nul} in the collation sequence is
undefined, and we want one of \code{<}, \code{==} and \code{>} to be
true for any comparison.)

Missing values (\code{\LinkA{NA}{NA}}) and \code{\LinkA{NaN}{NaN}} values are
regarded as non-comparable even to themselves, so comparisons
involving them will always result in \code{NA}.  Missing values can
also result when character strings are compared and one is not valid
in the current collation locale. 

Language objects such as symbols and calls are deparsed to
character strings before comparison.
\end{Details}
\begin{Value}
A vector of logicals indicating the result of the element by element
comparison.  The elements of shorter vectors are recycled as
necessary.

Objects such as arrays or time-series can be compared this way
provided they are conformable.
\end{Value}
\begin{Section}{S4 methods}
These operators are members of the S4 \code{\LinkA{Compare}{Compare}} group generic,
and so methods can be written for them individually as well as for the
group generic (or the \code{Ops} group generic), with arguments
\code{c(e1, e2)}.
\end{Section}
\begin{Note}\relax
Do not 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 unusual
can happen, you should use the \code{\LinkA{identical}{identical}} function
instead.

For numerical and complex values, remember \code{==} and \code{!=} do
not allow for the finite representation of fractions, nor for rounding
error. Using \code{\LinkA{all.equal}{all.equal}} with \code{identical} is almost
always preferable.  See the examples.
\end{Note}
\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{\LinkA{factor}{factor}} for the behaviour with factor arguments.

\code{\LinkA{Syntax}{Syntax}} for operator precedence.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
x <- stats::rnorm(20)
x < 1
x[x > 0]

x1 <- 0.5 - 0.3
x2 <- 0.3 - 0.1
x1 == x2                           # FALSE on most machines
identical(all.equal(x1, x2), TRUE) # TRUE everywhere
\end{ExampleCode}
\end{Examples}

