Learn R Programming

gsDesign2 (version 1.1.3)

fastlag: 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)

Value

a vector that begins with first and is followed by x

with its final value removed

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.

Examples

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

Run the code above in your browser using DataLab