Modify a vector of dates by a random quantity in [-e, e]. The distribution decreases exponentially, with rate 1/2

time_jitter(x, e)

Arguments

x

Numeric or Date vector.

e

Numeric. Semi-width of the jittering interval.

Value

Vector of the same size and type as x with jittered values.

Examples

spreadrate:::time_jitter(1:10, 1) # Numeric input
#> [1] 1 2 4 4 5 6 7 7 9 11
spreadrate:::time_jitter(Sys.Date() + 1:10, 1) # Date input
#> [1] "2019-07-17" "2019-07-19" "2019-07-20" "2019-07-22" "2019-07-22" #> [6] "2019-07-22" "2019-07-25" "2019-07-24" "2019-07-27" "2019-07-28"
## Distribution of jittering x <- seq.int(1e3) xj <- spreadrate:::time_jitter(x, 5) barplot(table(x - xj))