cum_sum: Cumulative sum

Description Usage Arguments Value Examples

View source: R/ff_cum_sum.R

Description

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

Usage

1
cum_sum(x, col_name, out_name = NULL)

Arguments

x

data frame with class Date or POSIXct in the first column and numeric on the others.

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 data frame.

Value

The same data frame but with the new series.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# 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'], y = cuevas[ , 'p_cum'],
     col = 'red', type = 'l',
     xlab = 'Date', ylab = 'Pcum(mm)')

hydrotoolbox documentation built on July 9, 2021, 1:06 a.m.