Section 16 Vector Operation: Logical
A logical vector is
TRUEorFALSEIt is the R representation of Boolean data
The logical vector is very helpful for comparisons
A logical vector is created by typing TRUE or FALSE (uppercase without the quote marks)
R also assume
TandFas shorthand forTRUEorFALSEEnclosing
TRUEorFALSEby quotes will render it to a character vectorFunction to identify the object type:
class, typeof, modeOther functions to check the object type as logical:
is.logical
16.2 Examples: comparison
Ruses operators==,!=,>,<,>=and<=for logical comparisons
| Operator | Explanation | Example |
|---|---|---|
== |
x EQUAL y? |
x == y |
!= |
x NOT EQUAL y? |
x != y |
< |
x LESS THAN y? |
x < y |
<= |
x LESS THAN OR EQUAL y? |
x <= y |
> |
x GREATER THAN y? |
x > y |
>= |
x GREATER THAN OR EQUAL y? |
x >= y |
16.3 Examples: more comparisons
Ruses operators==,>,<,>=and<=for comparisonsRalso uses operators!(NOT),&(AND) and|(OR)
| Operator | Meaning | X | Y | Decision | Example |
|---|---|---|---|---|---|
& |
AND |
TRUE | TRUE | TRUE | X & Y |
& |
AND |
TRUE | FALSE | FALSE | X & Y |
& |
AND |
FALSE | TRUE | FALSE | X & Y |
& |
AND |
FALSE | FALSE | FALSE | X & Y |
| | | OR |
TRUE | TRUE | TRUE | X | Y |
| | | OR |
TRUE | FALSE | TRUE | X | Y |
| | | OR |
FALSE | TRUE | TRUE | X | Y |
| | | OR |
FALSE | FALSE | FALSE | X | Y |