Comparison Operators

DESCRIPTION:

Returns a vector of logicals which is the result of the comparison applied to each element of the input vectors.

USAGE:

e1 op e2 
<BR>
<BR>

ARGUMENTS:

op
one of >, <, >=, <=, == or !=.

REQUIRED ARGUMENTS:

e1, e2
numeric, character, or complex objects. Missing values ( NAs) are allowed.

VALUE:

logical vector with FALSE or TRUE in each element according to the truth of the element-wise comparison of the operands.

The comparison operators are:

OPERATOR MEANING > greater than < less than >= greater than or equal to <= less than or equal to == equal to != not equal to

DETAILS:

An NA element of e1 or e2 results in an NA element of the answer.

These are members of the Ops group of generic functions.

For complex data op orders first on the real part, then on the imaginary part if necessary. For character data, ordering is by the ASCII character set.

See section 5.6 of Becker, Chambers and Wilks for the rules for dealing with operands with attributes.

NOTE:

To test for missing values use is.na.

To test for a NULL value use is.null.

When comparing floating point numbers, you may wish to allow for small differences, e.g. abs(x-y) < 1E-6 rather than testing for exact equality using

identical(x,y) is useful in many cases in place of x==y, e.g. for non-numerical objects, or to compare objects of different lengths. x == y .

WARNING:

You need to leave a space between a " <" operator and a negative number because " <-" is always interpreted as the assignment operator. This is a very unusual case, spaces generally make no difference.

Classes:

This function will be used as the default method for classes that do not inherit a specific method for the function or for the Ops group of functions. The result will retain the class and the attributes. If this behavior is not appropriate, the designer of the class should provide a method for the function or for the Ops group

SEE ALSO:

, , , , , , , .

EXAMPLES:

a > b      # true when 'a' greater than 'b' 
x[x > 100]      # all 'x' values larger than 100 
state == "Wyoming"  

x == NA    # probably not what you want
is.na(x)   # indicates which elements are missing

x == NULL  # probably not what you want
is.null(x)
identical(x, NULL)

length(x)==1 && class(x) == "logical" && x
identical(x, T) # easier way