View source: R/bin-averaging.R
AverageByIndex | R Documentation |
Calculate bin averages defined by vector index positions.
AverageByIndex(x, ind, na.rm = TRUE)
x |
numeric vector for which to compute bin averages according to the
indices given in |
ind |
numeric vector of index positions specifying the binning windows to average over, see details. |
na.rm |
a logical value indicating whether ‘NA’ values should be
stripped before the computation proceeds. Defaults to |
Averaging bins are defined consecutively from the first index position to the index position one before the next index, i.e., closed on the left and open on the right (the right end of the first bin does not overlap with the left end of the second bin, and so on).
But note that the final bin is treated separately: if the last index
coincides with the last data point of x
, this point _is_ included in
the last bin average, else the bin is treated analogously to the other bins
(see examples).
a numeric vector of length length(ind) - 1
with the mean
values of each bin from the break points defined by ind
.
Thomas Münch
x <- rnorm(20)
# final bin includes final data point:
AverageByIndex(x, ind = c(1, 7, 13, 17, 20))
# final index is not final data point:
AverageByIndex(x, ind = c(1, 7, 13, 17))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.