subset_if | R Documentation |
The x %[if]% cond
operator
selects elements from vector/matrix/array x
,
for which the result of cond(x)
returns TRUE
.
And the x %[!if]% cond
operator
selects elements from vector/matrix/array x
,
for which the result of cond(x)
returns FALSE
.
The x %unreal =% repl
operator
modifies all unreal (NA, NaN, Inf, -Inf
) values of x
with replacement value repl
.
Thus,
x %unreal =% repl
,
is the same as,
x[is.na(x) | is.nan(x) | is.infinite(x)] <- repl
x %[if]% cond
x %[!if]% cond
x %unreal =% repl
x |
a vector, matrix, or array. |
cond |
a (possibly anonymous) function that returns a |
repl |
the replacement value. |
For the x %[if]% cond
and x %[!if]% cond
operators:
The subset_if - operators all return a vector with the selected elements.
For the x %unreal =% repl
operator:
The x %unreal =% repl
operator does not return any value:
It is an in-place modifier, and thus modifies x
directly.
The object x
is modified such that all
NA
, NaN
, Inf
, and -Inf
elements are replaced with repl
.
tinycodet_dry
x <- c(-10:9, NA, NA)
object_with_very_long_name <- matrix(x, ncol=2)
print(object_with_very_long_name)
object_with_very_long_name %[if]% \(x)x %in% 1:10
object_with_very_long_name %[!if]% \(x)x %in% 1:10
x <- c(1:9, NA, NaN, Inf)
print(x)
x %unreal =% 0 # same as x[is.na(x)|is.nan(x)|is.infinite(x)] <- 0
print(x)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.