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

vec_detect_complete

Complete


Description

vec_detect_complete() detects "complete" observations. An observation is considered complete if it is non-missing. For most vectors, this implies that vec_detect_complete(x) == !vec_equal_na(x).

For data frames and matrices, a row is only considered complete if all elements of that row are non-missing. To compare, !vec_equal_na(x) detects rows that are partially complete (they have at least one non-missing value).

Usage

vec_detect_complete(x)

Arguments

x

A vector

Details

A record type vector is considered complete if any field is non-missing.

Value

A logical vector with the same size as x.

See Also

Examples

x <- c(1, 2, NA, 4, NA)

# For most vectors, this is identical to `!vec_equal_na(x)`
vec_detect_complete(x)
!vec_equal_na(x)

df <- data_frame(
  x = x,
  y = c("a", "b", NA, "d", "e")
)

# This returns `TRUE` where all elements of the row are non-missing.
# Compare that with `!vec_equal_na()`, which detects rows that have at
# least one non-missing value.
df2 <- df
df2$all_non_missing <- vec_detect_complete(df)
df2$any_non_missing <- !vec_equal_na(df)
df2

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.