custom_agg_func <- function(x, y, n_out) {
bin_width <- floor(length(x)/n_out)
x_idx <- seq(floor(bin_width / 2), bin_width * n_out, bin_width)
y_mat <- y[1:(bin_width * n_out)] %>%
matrix(nrow = bin_width)
y_agg <- apply(y_mat, 2, quantile, probs = 0.25)
return(list(x = x[x_idx], y = y_agg))
}
data(noise_fluct)
agg <- custom_func_aggregator$new(
aggregation_func = custom_agg_func, interleave_gaps = TRUE
)
d_agg <- agg$aggregate(
x = noise_fluct$time, y = noise_fluct$f500, n_out = 1000
)
plotly::plot_ly(x = d_agg$x, y = d_agg$y, type = "scatter", mode = "lines")
Run the code above in your browser using DataLab