This function augments a data frame by adding cumulative sum columns for specified variables.
Arguments
- .data
A data frame to augment.
- .value
A column name or names for which to compute the cumulative sum.
- .names
Optional. A character vector of names for the new cumulative sum columns. Defaults to "auto", which generates names based on the original column names.
- .initial_value
A numeric value to start the cumulative sum from. Defaults to 0.
Details
The function takes a data frame and a column name (or names) and computes the cumulative sum for each specified column, starting from an initial value. If the column names are not provided, it will throw an error.
See also
Other Utility Functions:
convert_snake_to_title_case()
,
generate_caption()
,
get_attributes()
,
rand_walk_column_names()
,
rand_walk_helper()
,
running_quantile()
,
std_cum_max_augment()
,
std_cum_mean_augment()
,
std_cum_min_augment()
,
std_cum_prod_augment()
Examples
df <- data.frame(x = 1:5, y = 6:10)
std_cum_sum_augment(df, .value = x)
#> # A tibble: 5 × 3
#> x y cum_sum_x
#> <int> <int> <dbl>
#> 1 1 6 1
#> 2 2 7 3
#> 3 3 8 6
#> 4 4 9 10
#> 5 5 10 15
std_cum_sum_augment(df, .value = y, .names = c("cumsum_y"))
#> # A tibble: 5 × 3
#> x y cumsum_y
#> <int> <int> <dbl>
#> 1 1 6 6
#> 2 2 7 13
#> 3 3 8 21
#> 4 4 9 30
#> 5 5 10 40