| naCompare {omnibus} | R Documentation |
Compare values using <, <=, >, >=, !=, and == (robust to NAs)
Description
This function and set of operators perform simple (vectorized) comparisons using <, <=, >, >=, !=, or == between values and always returns TRUE or FALSE. TRUE only occurs if the condition can be evaluated and it is TRUE. FALSE is returned if the condition is FALSE or it cannot be evaluated.
Usage
naCompare(op, x, y)
x %<na% y
x %<=na% y
x %==na% y
x %!=na% y
x %>na% y
x %>=na% y
Arguments
op |
Character, the operation to perform: |
x, y |
Vectors of numeric, character, |
Value
Vector of logical values.
Examples
naCompare('<', c(1, 2, NA), c(10, 1, 0))
naCompare('<', c(1, 2, NA), 10)
naCompare('<', c(1, 2, NA), NA)
# compare to:
NA < 5
NA < NA
# same operations with operators:
1 %<na% 2
1 %<na% NA
3 %==na% 3
NA %==na% 3
4 %!=na% 4
4 %!=na% NA
5 %>=na% 3
5 %>=na% NA
3 %==na% c(NA, 1, 2, 3, 4)
# compare to:
1 < 2
1 < NA
3 == 3
NA == 3
4 != 4
4 != NA
5 >= 3
5 >= NA
3 == c(NA, 1, 2, 3, 4)
[Package omnibus version 1.2.13 Index]