first: Identify the first and last elements for each run in a vector

Description Usage Arguments Details Examples

View source: R/first.R

Description

For an input vector which contains a sequence of runs, these functions identify the first and last points in each run. They return a logical vector.

Usage

1
2
3
first(x, na.as.group = F)

last(x, na.as.group = F)

Arguments

x

a vector with runs

a

logical vector; TRUE if it is the first or last of a run

Details

These functions use rle to compute a run length encoding for the vector and extract the first and last elements in each run from the lengths of each run.

Examples

1
2
first(c(1,1,2,2))
last(c(1,1,2,2))

jasonelaw/nrsa documentation built on Nov. 8, 2019, 11:34 a.m.