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

lag_lead

Fast lead/lag for vectors


Description

Analogous function for lead and lag in dplyr by wrapping data.table's shift.

Usage

lead(x, n = 1L, fill = NA)

lag(x, n = 1L, fill = NA)

Arguments

x

A vector

n

a positive integer of length 1, giving the number of positions to lead or lag by. Default uses 1

fill

Value to use for padding when the window goes beyond the input length. Default uses NA

Value

A vector

See Also

Examples

lead(1:5)
lag(1:5)
lead(1:5,2)
lead(1:5,n = 2,fill = 0)

tidyft

Tidy Verbs for Fast Data Operations by Reference

v0.4.5
MIT + file LICENSE
Authors
Tian-Yuan Huang [aut, cre] (<https://orcid.org/0000-0002-3591-4203>)
Initial release

We don't support your browser anymore

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