roll_fun | R Documentation |
It provides a generic function to rolling table columns.
Internally it is using rollapplyr
from package zoo
.
roll_fun(
x,
col_name = "last",
k,
pos = "c",
FUN,
...,
out_name = NULL,
from = NULL,
to = NULL
)
x |
data frame (or tibble) with class |
col_name |
string vector with the column(s) name(s) of the series to roll.
The default value uses the |
k |
numeric vector with the windows size. E.g.: |
pos |
string vector with the position of the windows:
|
FUN |
the function to be applied. |
... |
optional arguments to |
out_name |
optional. String vector with new column names. If you set
it as |
from |
optional. String value for |
to |
optional. String value for |
The same table but with the rolling series.
# read guido daily streamflow records
path <- system.file('extdata', 'snih_qd_guido.xlsx',
package = 'hydrotoolbox')
# read and apply the function
qd_guido <-
read_snih(path = path, by = 'day', out_name = 'q(m3/s)') %>%
roll_fun(k = 5, FUN = mean, na.rm = TRUE,
out_name = 'q_smooth')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.