Logical Operators

DESCRIPTION:
Returns a logical object with attributes preserved. The operators are "and", "or", "not" and "exclusive or".

USAGE:
e1 & e2
e1 | e2
! e1
xor(e1, e2)

REQUIRED ARGUMENTS:
e1,e2:
logical objects. Missing values (NAs) are allowed.

VALUE:
logical result of and-ing, or-ing, negation, or exclusive or-ing. For all but negation, the result is as long as the longer of the operands.

NOTE:
An exclamation mark (!) beginning an expression always escapes to the operating system rather than meaning "not". Use curly braces or parentheses to surround an expression if the "not" operator is the first character.

CLASSES:
This function will be used as the default method for classes that do not inherit a specifc 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.

DETAILS:
Results corresponding to in the operands will be either a logical value or an NA, depending on whether the other operand uniquely determines the answer; for example, NA|TRUE must be TRUE, and NA&FALSE must be FALSE. See section 5.1.5 of Becker, Chambers and Wilks for the rules for dealing with operands with attributes.

These are members of the Ops group of generic functions.


SEE ALSO:
if for || (sequential or) and && (sequential and). Comparison .

EXAMPLES:
attach(cu.summary)

cu.summary[Country=="USA" | Country=="Japan/USA", | Country == "Japan", ] # cars made in USA or Japan or both

cu.summary[!is.na(Reliability) & !is.na(Mileage),] # rows of cu.summary with no NA's in either Reliability or Mileage

safe <- !is.na(Mileage) cu.summary[xor(Mileage > 21, Mileage < 27) & safe, ] # cars with Mileages outside the interquartile range # exclusive of NA's

a <- c(T,F,NA) outer(a,a,"&") # logic table for &