Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

vec_equal

Test if two vectors are equal


Description

vec_equal_na() tests a special case: equality with NA. It is similar to is.na but:

  • Considers the missing element of a list to be NULL.

  • Considered data frames and records to be missing if every component is missing. This preserves the invariant that vec_equal_na(x) is equal to vec_equal(x, vec_init(x), na_equal = TRUE).

Usage

vec_equal(x, y, na_equal = FALSE, .ptype = NULL)

vec_equal_na(x)

Arguments

x

Vectors with compatible types and lengths.

y

Vectors with compatible types and lengths.

na_equal

Should NA values be considered equal?

.ptype

Override to optionally specify common type

Value

A logical vector the same size as. Will only contain NAs if na_equal is FALSE.

Dependencies

Examples

vec_equal(c(TRUE, FALSE, NA), FALSE)
vec_equal(c(TRUE, FALSE, NA), FALSE, na_equal = TRUE)
vec_equal_na(c(TRUE, FALSE, NA))

vec_equal(5, 1:10)
vec_equal("d", letters[1:10])

df <- data.frame(x = c(1, 1, 2, 1, NA), y = c(1, 2, 1, NA, NA))
vec_equal(df, data.frame(x = 1, y = 2))
vec_equal_na(df)

vctrs

Vector Helpers

v0.3.8
MIT + file LICENSE
Authors
Hadley Wickham [aut], Lionel Henry [aut, cre], Davis Vaughan [aut], data.table team [cph] (Radix sort based on data.table's forder() and their contribution to R's order()), RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.