A function to help build random walks by mutating a data frame.
Value
A modified data frame/tibble with the following columns added:
cum_sum
: Cumulative sum ofy
.cum_prod
: Cumulative product ofy
.cum_min
: Cumulative minimum ofy
.cum_max
: Cumulative maximum ofy
.cum_mean
: Cumulative mean ofy
.
Details
A function to help build random walks by mutating a data frame. This mutation
adds the following columns to the data frame: cum_sum
, cum_prod
, cum_min
,
cum_max
, and cum_mean
. The function is used internally by certain functions
that generate random walks.
See also
Other Utility Functions:
convert_snake_to_title_case()
,
generate_caption()
,
get_attributes()
,
rand_walk_column_names()
,
running_quantile()
,
std_cum_max_augment()
,
std_cum_mean_augment()
,
std_cum_min_augment()
,
std_cum_prod_augment()
,
std_cum_sum_augment()
Examples
df <- data.frame(
walk_number = factor(rep(1L:25L, each = 30L)),
x = rep(1L:30L, 25L),
y = rnorm(750L, 0L, 1L)
)
rand_walk_helper(df, 100)
#> # A tibble: 750 × 8
#> walk_number x y cum_sum cum_prod cum_min cum_max cum_mean
#> <fct> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 1 1 0.406 100. 141. 100. 100. 100.
#> 2 1 2 0.947 101. 274. 100. 101. 101.
#> 3 1 3 2.06 103. 838. 100. 102. 101.
#> 4 1 4 1.35 105. 1972. 100. 102. 101.
#> 5 1 5 0.812 106. 3573. 100. 102. 101.
#> 6 1 6 0.0815 106. 3865. 100. 102. 101.
#> 7 1 7 -1.13 105. -501. 98.9 102. 101.
#> 8 1 8 -0.504 104. -248. 98.9 102. 101.
#> 9 1 9 2.64 107. -904. 98.9 103. 101.
#> 10 1 10 0.595 107. -1442. 98.9 103. 101.
#> # ℹ 740 more rows