As well as numerical vectors, . allows manipulation of logical quantities. The elements of a logical vectors have just two possible values, represented formally as FALSE and TRUE. These are usually abbreviated as F and T, respectively.
Logical vectors are generated by conditions. For example
temp <- x>13
sets temp as a vector of the same length as x with values F corresponding to elements of x where the condition is not met and T where it is.
The logical operators are <, <=, >, >=, ==
for exact equality and != for inequality. In addition if c1
and c2 are logical expressions, then c1
&
c2 is their
intersection, c1
|
c2 is their union and !
c1 is the
negation of c1.
Logical vectors may be used in ordinary arithmetic, in which case they are coerced into numeric vectors, F becoming 0 and T becoming 1. However there are situations where logical vectors and their coerced numeric counterparts are not equivalent, for example see the next subsection.