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

wf

Get the index of the first/last TRUE


Description

A quick C implementation for “which.first” (head(which(x), 1)) and “which.last” (tail(which(x), 1)).

Usage

wf(x, use.names = TRUE)

wl(x, use.names = TRUE)

Arguments

x

[logical]
Logical vector.

use.names

[logical(1)]
If TRUE and x is named, the result is also named.

Value

[integer(1) | integer(0)]. Returns the index of the first/last TRUE value in x or an empty integer vector if none is found. NAs are ignored.

Examples

wf(c(FALSE, TRUE))
wl(c(FALSE, FALSE))
wf(NA)

checkmate

Fast and Versatile Argument Checks

v2.0.0
BSD_3_clause + file LICENSE
Authors
Michel Lang [cre, aut] (<https://orcid.org/0000-0001-9754-0393>), Bernd Bischl [ctb]
Initial release

We don't support your browser anymore

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