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 |
|
Note that in an if expression, && and || are often used to perform logical calculations that are only needed to yield a single-element logical vector. However, the potential risk of using && is that if it is made...