Using logical functions
A logical vector only takes TRUE
or FALSE
and is mostly used to filter data. In practice, it is common to create joint conditions by multiple logical vectors where a number of logical operators and functions may involve.
Logical operators
Like many other programming languages, R enables a few operators to do basic logical calculations. The following table demonstrates what they do:
Symbol |
Description |
Example |
Result |
|
Vectorized AND |
|
|
|
Vectorized OR |
|
|
|
Univariate AND |
|
|
|
Univariate OR |
|
|
|
Vectorized NOT |
|
|
|
Vectorized IN |
c |
|
Get Learning R Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.