Learn R Programming

oce (version 0.8-3)

binAverage: Bin-average a vector y, based on x values

Description

Bin-average a vector y, based on x values

Usage

binAverage(x, y, xmin, xmax, xinc)

Arguments

x
a vector of numerical values.
y
a vector of numerical values.
xmin
x value at the lower limit of first bin; the minimum x will be used if this is not provided.
xmax
x value at the upper limit of last bin; the maximum x will be used if this is not provided.
xinc
width of bins, in terms of x value; 1/10th of xmax-xmin will be used if this is not provided.

Value

  • A list with two elements: x, the mid-points of the bins, and y, the average y value in the bins.

Details

The y vector is averaged in bins defined for x. Missing values in y are ignored.

Examples

Run this code
library(oce)
data(co2)
plot(co2)
avg <- binAverage(time(co2), co2, 1950, 2000, 2)
lines(avg$x, avg$y, col='red')

Run the code above in your browser using DataLab