is_different | R Documentation |
NA
as values to be comparedis_different()
and is_equal()
performs comparison tests, considering
NA
values as legitimate values (see examples).
is_different(x, y)
is_equal(x, y)
cumdifferent(x)
num_cycle(x)
x , y |
Vectors to be compared. |
cum_different()
allows to identify groups of continuous rows that have
the same value. num_cycle()
could be used to identify sub-groups that
respect a certain condition (see examples).
is_equal(x, y)
is equivalent to
(x == y & !is.na(x) & !is.na(y)) | (is.na(x) & is.na(y))
, and
is_different(x, y)
is equivalent to
(x != y & !is.na(x) & !is.na(y)) | xor(is.na(x), is.na(y))
.
A vector of the same length as x
.
v <- c("a", "b", NA)
is_different(v, "a")
is_different(v, NA)
is_equal(v, "a")
is_equal(v, NA)
d <- dplyr::tibble(group = c("a", "a", "b", "b", "a", "b", "c", "a"))
d |>
dplyr::mutate(
subgroup = cumdifferent(group),
sub_a = num_cycle(group == "a")
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.