use_first_valid_of: Returns first non-NA value from a set of vectors.

View source: R/janitor_deprecated.R

use_first_valid_ofR Documentation

Returns first non-NA value from a set of vectors.


At each position of the input vectors, iterates through in order and returns the first non-NA value. This is a robust replacement of the common ifelse(!, x, ifelse(!, y, z)). It's more readable and handles problems like ifelse's inability to work with dates in this way.


use_first_valid_of(..., if_all_NA = NA)



the input vectors. Order matters: these are searched and prioritized in the order they are supplied.


what value should be used when all of the vectors return NA for a certain index? Default is NA.


Returns a single vector with the selected values.


Deprecated, do not use in new code. Use dplyr::coalesce() instead.

See Also


janitor documentation built on Feb. 16, 2023, 10:16 p.m.