Skip to content

Instantly share code, notes, and snippets.

@DavisVaughan
Created November 3, 2020 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavisVaughan/c81ce7eab7eac22daa06b23480ac6c0c to your computer and use it in GitHub Desktop.
Save DavisVaughan/c81ce7eab7eac22daa06b23480ac6c0c to your computer and use it in GitHub Desktop.
tsibble-to-slider.R
x <- c(1, 2, 3, 4, 5)
# partial = FALSE -> only "complete" windows are allowed
#
# `size = 2, align = right` translates to:
# "the current value, and one before it"
#
tsibble::slide(x, identity, .size = 2, .partial = FALSE, .align = "right")
#> [[1]]
#> [1] NA
#>
#> [[2]]
#> [1] 1 2
#>
#> [[3]]
#> [1] 2 3
#>
#> [[4]]
#> [1] 3 4
#>
#> [[5]]
#> [1] 4 5
# complete = TRUE -> only "complete" windows are allowed
#
# `before = 1` translates to:
# "the current value, and one before it"
slider::slide(x, identity, .before = 1, .complete = TRUE)
#> [[1]]
#> NULL
#>
#> [[2]]
#> [1] 1 2
#>
#> [[3]]
#> [1] 2 3
#>
#> [[4]]
#> [1] 3 4
#>
#> [[5]]
#> [1] 4 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment