#' Create groups per cumsum
#'
#' @name col_cumsum_group
#' @param x A data frame
#' @param threshold An integer
#' @return A character vectoru
#'
#' @export
#' @rdname col_cumsum_group
#'
col_cumsum_group <- function(x, threshold) {
cumsum <- 0
group <- 1
result <- numeric()
for (i in 1:length(x)) {
cumsum <- cumsum + x[i]
if (cumsum > threshold) {
group <- group + 1
cumsum <- x[i] }
result = c(result, group)}
return (result)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.