View source: R/ms_synchronize_timestep.R
ms_synchronize_timestep | R Documentation |
Set the sample interval of a data.frame
in MacroSheds
format (see MacroSheds EDI)
by interpolation (for upsampling) or aggregation (for downsampling).
ms_synchronize_timestep(
d,
desired_interval,
round_method = "floor",
interpolate_method = "linear",
interpolate_limit,
summary_fun,
quiet = FALSE
)
d |
|
desired_interval |
character. Input that can be parsed by the "by" parameter of base::seq.POSIXt, e.g. "5 mins", "1 day", "1 month". |
round_method |
character. If "floor" (the default), dates or datetimes will be shifted
backward to the nearest |
interpolate_method |
character. One of:
|
interpolate_limit |
numeric. The maximum number of consecutive points to interpolate. |
summary_fun |
optional character. One of "mean" or "sum". The function that will be used to summarize data if desired_interval is larger than the input data in d. |
quiet |
logical. Should warnings be printed to console. |
returns a tibble
with data in the new desired_interval with a
ms_interp column indicating if a value was interpolated.
Spencer Rhea
Mike Vlah, vlahm13@gmail.com
Wes Slaughter
### Load some MacroSheds data:
ms_root = 'data/macrosheds'
ms_download_core_data(macrosheds_root = ms_root,
domains = 'hbef')
d <- ms_load_product(macrosheds_root = ms_root,
prodname = 'stream_chemistry',
domains = 'hbef',
filter_vars = c('NO3_N', 'Na', 'Mg', 'SO4_S'))
### interpolate to 15-minute intervals, but don't fill gaps larger than 24 hours
ms_synchronize_timestep(d, '15 min', 96)
### aggregate samples to weekly interval by mean, and fill gaps of < 3 weeks
ms_synchronize_timestep(d, '1 week', 3, summary_fun = 'mean')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.