View source: R/zoo_aggregate.R
zoo_aggregate | R Documentation |
Aggregate Cases in Zoo Time Series
zoo_aggregate(x = NULL, new_time = NULL, f = mean, ...)
x |
(required, zoo object) Time series to aggregate. Default: NULL |
new_time |
(optional, zoo object, keyword, or time vector) New time to aggregate
|
f |
(optional, quoted or unquoted function name) Name of a standard or custom function to aggregate numeric vectors. Typical examples are |
... |
(optional, additional arguments) additional arguments to |
zoo object
Other zoo_functions:
zoo_name_clean()
,
zoo_name_get()
,
zoo_name_set()
,
zoo_permute()
,
zoo_plot()
,
zoo_resample()
,
zoo_smooth_exponential()
,
zoo_smooth_window()
,
zoo_time()
,
zoo_to_tsl()
,
zoo_vector_to_matrix()
#full range of calendar dates
x <- zoo_simulate(
rows = 1000,
time_range = c(
"0000-01-01",
as.character(Sys.Date())
)
)
#plot time series
if(interactive()){
zoo_plot(x)
}
#find valid aggregation keywords
x_time <- zoo_time(x)
x_time$keywords
#mean value by millennia (extreme case!!!)
x_millennia <- zoo_aggregate(
x = x,
new_time = "millennia",
f = mean
)
if(interactive()){
zoo_plot(x_millennia)
}
#max value by centuries
x_centuries <- zoo_aggregate(
x = x,
new_time = "centuries",
f = max
)
if(interactive()){
zoo_plot(x_centuries)
}
#quantile 0.75 value by centuries
x_centuries <- zoo_aggregate(
x = x,
new_time = "centuries",
f = stats::quantile,
probs = 0.75 #argument of stats::quantile()
)
if(interactive()){
zoo_plot(x_centuries)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.