rawr_ops | R Documentation |
Some useful binary operators.
x %ni% table
x %sinside% interval
x %winside% interval
x %inside% interval
a %==% b
a %|% b
object %:% range
x |
vector or |
table |
vector or |
interval |
numeric vector of length two representing the interval |
a , b |
raw, logical, "number-like" vectors or objects |
object |
a named vector or list, a matrix or data frame |
range |
a numeric or character vector of length two with the indices
or names from |
%ni%
is the negation of %in%
.
%winside%
and %sinside%
return a logical vector
indicating if x
is weakly or strongly inside interval
.
%inside%
is an alias for %winside%
to preserve existing
code.
%==%
is an operator combining the qualities of ==
and %in%
to compare vectors in a pairwise manner which may
include NA
s.
%||%
is useful for a function, f
, that may return a value
or NULL
; however if NULL
is the return value of f
, it
is desirable to return some other default value.
%:%
is useful for obtaining a range of a vector (usually
colnames
or names
of a matrix or data frame) by literal
character strings rather than by index.
==
, %in%
, ||
## notin
1:5 %ni% 3:5
## weakly/strongly inside
c(0, 4) %winside% c(0, 4)
c(0, 4) %sinside% c(0, 4)
-5:5 %winside% c(0, 5)
-5:5 %sinside% c(0, 5)
## %in% plus ==
a <- c(1, NA, 2)
b <- c(2, NA, 1)
## not desired
a == b # FALSE NA FALSE
a %in% b # TRUE TRUE TRUE
## desired results
a %==% b # FALSE TRUE FALSE
# NULL | TRUE # logical(0)
NULL %|% TRUE # TRUE
# logical() | TRUE # logical(0)
logical() %|% TRUE # TRUE
1:5 %:% c(3, 5)
letters %:% c('e', 'n')
## these are equivalent
mtcars %:% c('hp', 'vs')
mtcars %:% c(4, 8)
names(mtcars[, 4:8])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.