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

lags..html

Get lagging or leading values


Description

Find the "previous" or "next" values in a vector. Useful for comparing values behind or ahead of the current values.

Usage

lags.(x, n = 1L, default = NA)

leads.(x, n = 1L, default = NA)

Arguments

x

a vector of values

n

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

default

value used for non-existent rows. Defaults to NA.

Examples

x <- 1:5

leads.(x, 1)
lags.(x, 1)

# Also works inside of `mutate.()`
test_df <- tidytable(x = 1:5)

test_df %>%
  mutate.(lag_x = lags.(x))

tidytable

Tidy Interface to 'data.table'

v0.6.1
MIT + file LICENSE
Authors
Mark Fairbanks [aut, cre], Abdessabour Moutik [ctb], Matt Carlson [ctb], Ivan Leung [ctb], Ross Kennedy [ctb]
Initial release

We don't support your browser anymore

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