Learn R Programming

hutilscpp (version 0.10.7)

which_firstNA: First/last position of missing values

Description

Introduced in v 1.6.0

Usage

which_firstNA(x)

which_lastNA(x)

Value

The position of the first/last missing value in x.

Arguments

x

An atomic vector.

Examples

Run this code
N <- 1e8
N <- 1e6  # for CRAN etc
x <- c(1:1e5, NA, integer(N))
bench_system_time(which.max(is.na(x))) # 123ms
bench_system_time(Position(is.na, x))  #  22ms
bench_system_time(which_firstNA(x))    #  <1ms

Run the code above in your browser using DataLab