logic_ops | R Documentation |
Additional logic operators:
The x %xor% y
operator is the "exclusive-or" operator,
the same as xor(x, y)
.
The x %n&%
operator is the "not-and" operator,
the same as (!x) & (!y)
.
The x %out% y
operator is the same as !x %in% y
.
The x %?=% y
operator checks if x
and y
are both unreal or unknown (i.e. NA, NaN, Inf, -Inf).
The n %=numtype% numtype
operator checks
for every value of numeric vector n
if it can be considered a number belonging to type numtype
.
The s %=strtype% strtype
operator checks
for every value of character vector s
if it can seen as a certain strtype
.
x %xor% y
x %n&% y
x %out% y
x %?=% y
n %=numtype% numtype
s %=strtype% strtype
x , y |
see Logic. |
n |
a numeric vector. |
numtype |
a single string giving the numeric type to be checked. |
s |
a character vector. |
strtype |
a single string giving the string type to be checked. |
For argument numtype
, the following options are supported:
"~0"
: zero, or else a number whose absolute value is smaller than the
Machine tolerance (sqrt(.Machine$double.eps)
).
"B"
: binary numbers (exactly 0 or exactly 1);
"prop"
: proportions - numbers between 0 and 1 (exactly 0 or 1 is also allowed);
"I"
: Integers;
"odd"
: odd integers;
"even"
: even integers;
"R"
: Real numbers;
"unreal"
: infinity, NA, or NaN;
For argument strtype
, the following options are supported:
"empty"
: checks if the string only consists of empty spaces.
"unreal"
: checks if the string is NA, or if it has literal string "NA", "NaN" or "Inf",
regardless if it has leading or trailing spaces.
"numeric"
: checks if the string can be converted to a number,
disregarding leading and trailing spaces.
I.e. the string "5.0" can be converted to the the actual number 5.0
.
"special"
: checks if the string consists of only special characters.
A logical vector.
x <- c(TRUE, FALSE, TRUE, FALSE, NA, NaN, Inf, -Inf, TRUE, FALSE)
y <- c(FALSE, TRUE, TRUE, FALSE, rep(NA, 6))
outcome <- data.frame(
x = x, y = y,
"x %xor% y" = x %xor% y, "x %n&% y" = x %n&% y, "x %?=% y" = x %?=% y,
check.names = FALSE
)
print(outcome)
1:3 %out% 1:10
1:10 %out% 1:3
n <- c(0:5, 0:-5, 0.1, -0.1, 0, 1, Inf, -Inf, NA, NaN)
1e-20 %=numtype% "~0"
n[n %=numtype% "B"]
n[n %=numtype% "prop"]
n[n %=numtype% "I"]
n[n %=numtype% "odd"]
n[n %=numtype% "even"]
n[n %=numtype% "R"]
n[n %=numtype% "unreal"]
s <- c(" AbcZ123 ", " abc ", " 1.3 ", " !#$%^&*() ", " ", " NA ", " NaN ", " Inf ")
s[s %=strtype% "empty"]
s[s %=strtype% "unreal"]
s[s %=strtype% "numeric"]
s[s %=strtype% "special"]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.