Shift run length encoding <NA>

na_rle_shift(x, n = 1L)

Arguments

x

An object returned by na_rle() or list_of_na_rle().

n

An integer shifts the position. If positive, shifts to the right, otherwise to the left.

Examples

(x <- na_rle(c(1, NA, NA, 4:7, NA, NA, 10:15, NA)))
#> <Run Length Encoding <NA>[3]> #> $lengths: <int> 2 2 1 #> $indices: <int> 2 8 16
na_rle_shift(x, n = 2)
#> <Run Length Encoding <NA>[3]> #> $lengths: <int> 2 2 1 #> $indices: <dbl> 4 10 18
na_rle_shift(x, n = -5)
#> <Run Length Encoding <NA>[3]> #> $lengths: <int> 2 2 1 #> $indices: <dbl> -3 3 11