Logical vectors



next up previous contents
Next: Missing values Up: Simple manipulations; numbers Previous: Generating regular sequences

Logical vectors

As well as numerical vectors, S-PLUS allows manipulation of logical quantities. The elements of a logical vectors have just two possible values, represented formally as F (for `false') and T (for `true').

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.



Erik Moledor
Tue Jan 31 21:02:18 EST 1995