cum_sum: Cumulative sum

View source: R/ff_cum_sum.R

cum_sumR Documentation

Cumulative sum

Description

The function supports NA_real_ values. It could be very useful when dealing with incomplete precipitation series.

Usage

cum_sum(x, col_name, out_name = NULL)

Arguments

x

data frame or tibble with class Date or POSIX* in the first column.

col_name

string with column(s) name(s) where to apply the function.

out_name

optional. String with new column(s) name(s). If you set it as NULL, the function will overwrite the original table.

Value

The same table but with the new series.

Examples

## Not run: 
# set path to file
path <- system.file('extdata', 'ianigla_cuevas.csv',
         package = 'hydrotoolbox')

# read the file and add the new column with cumulative precipitation
cuevas <-
  read_ianigla(path = path) %>%
  cum_sum(col_name = 'Precip_Total', out_name = 'p_cum')

# plot it
plot(x = cuevas[ , 'date', drop = TRUE],
     y = cuevas[ , 'p_cum', drop = TRUE],
     col = 'red', type = 'l',
     xlab = 'Date', ylab = 'Pcum(mm)')

## End(Not run)



hydrotoolbox documentation built on Oct. 25, 2022, 1:05 a.m.