Generate a regular sequence that 'bounces' between the provided start_n
and end_n
values in increments by the by
value for the length of the length
value provided.
Examples
#By default, seq_bounce creates sequences by increments of 1
#The length argument accepts any positive integer
seq_bounce(start_n = 1, end_n = 5, length = 15)
#> [1] 1 2 3 4 5 4 3 2 1 2 3 4 5 4 3
#The by argument accepts any positive numeric
seq_bounce(start_n = 0, end_n = 10, length = 30, by = .247)
#> [1] 0.000 0.247 0.494 0.741 0.988 1.235 1.482 1.729 1.976 2.223 2.470 2.717
#> [13] 2.964 3.211 3.458 3.705 3.952 4.199 4.446 4.693 4.940 5.187 5.434 5.681
#> [25] 5.928 6.175 6.422 6.669 6.916 7.163
#The end_n value must be greater than the start_n value
#This will give you an error
try(seq_bounce(start_n = 0, end_n = -10, length = 15))
#> Error in seq_bounce(start_n = 0, end_n = -10, length = 15) :
#> ✖ `start_n` must be less than `end_n` not more than or equal to `end_n`
#> ! You've supplied: `start_n` == 0 and `end_n` == -10
#> ℹ Check the `start_n` and `end_n` inputs.
#Instead, reverse the values
seq_bounce(start_n = -10, end_n = 0, length = 15)
#> [1] -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 -1 -2 -3 -4