Learn R Programming

tidytable (version 0.5.1)

leads.: Lead and Lag

Description

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

Usage

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

lags.(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

Run this code
# NOT RUN {
x <- 1:5

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

test_df <- tidytable(x = 1:5)

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

# }

Run the code above in your browser using DataLab