Learn R Programming

BBmisc (version 1.5)

first: Find the index of first/last TRUE value in a logical vector.

Description

Find the index of first/last TRUE value in a logical vector.

Usage

first(x, na.omit = TRUE)

last(x, na.omit = TRUE)

Arguments

x
[logical] Logical vector.
na.omit
[logical(1)] Should NAs be omitted from x?. Default is TRUE.

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. If NAs are encountered before a TRUE and not omitted, the result is NA_integer_.