first_nonmissing: First nonmissing element in a vector

View source: R/first-nonmissing.R

first_nonmissingR Documentation

First nonmissing element in a vector

Description

Take the first value that isn't missing. Adapted from http://stackoverflow.com/a/40515261/1082435.

Usage

first_nonmissing(x, value_if_all_na = NULL, na_codes = NULL)

Arguments

x

A vector of values to collapse.

value_if_all_na

A scalar value to return if all elements are missing (i.e., they are all either NA, or one of the na_codes).

na_codes

A vector of codes that represent missing values.

Details

value_if_all_na and na_codesmust have the same data type as x.

If value_if_all_na is null, then an NA will be returned. If na_codes is null, then all non-NA values are considered.

Value

A scalar of converted names.

Author(s)

Will Beasley

Examples

first_nonmissing(c(NA, "b", "c"))
first_nonmissing(c(NA_character_, NA_character_))
first_nonmissing(character(0))

OuhscBbmc/OuhscMunge documentation built on March 2, 2024, 11:44 a.m.