fastlag: Find the "previous" values in a vector

View source: R/expected_event.R

fastlagR Documentation

Find the "previous" values in a vector

Description

Fast replacement of dplyr::lag for the simple case of n = 1L and always supplying a new value to insert at the beginning of the vector.

Usage

fastlag(x, first)

Arguments

x

A vector (length(x) > 0)

first

A single value (length(first) == 1)

Details

Important: this function is fast because it provides minimal safety checks. It relies on the coercion rules of c. For best results, x and first should be the same type of atomic vector, though it should be fine to mix numeric and integer vectors as long as your own code also doesn't rely on this distinction. It can also work on lists if needed.

Value

a vector that begins with first and is followed by x with its final value removed

Examples

gsDesign2:::fastlag(1:5, first = 100) == c(100, 1:4)


gsDesign2 documentation built on April 3, 2025, 9:39 p.m.