Fast mean calculations in non-overlapping bins
Computes the sample means in non-overlapping bins
binMeans(y, x, idxs = NULL, bx, na.rm = TRUE, count = TRUE, right = FALSE, ...)
y |
A |
x |
|
idxs |
A |
bx |
A |
na.rm |
If |
count |
If |
right |
If |
... |
Not used. |
binMeans(x, bx, right = TRUE)
gives equivalent results as
rev(binMeans(-x, bx = sort(-bx), right = FALSE))
, but is faster.
Data points where either of y
and x
is missing are dropped
(and therefore are also not counted). Non-finite values in y
are
not allowed and gives an error. Missing values in bx
are not allowed
and gives an error.
Henrik Bengtsson with initial code contributions by Martin Morgan [1].
[1] R-devel thread Fastest non-overlapping binning mean
function out there? on Oct 3, 2012
x <- 1:200 mu <- double(length(x)) mu[1:50] <- 5 mu[101:150] <- -5 y <- mu + rnorm(length(x)) # Binning bx <- c(0, 50, 100, 150, 200) + 0.5 y_s <- binMeans(y, x = x, bx = bx) plot(x, y) for (kk in seq_along(y_s)) { lines(bx[c(kk, kk + 1)], y_s[c(kk, kk)], col = "blue", lwd = 2) }
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.