Average the values of a vector `f(x,y)`

in bins defined on
vectors `x`

and `y`

. A common example might be averaging
spatial data into location bins.

binMean2D(
x,
y,
f,
xbreaks,
ybreaks,
flatten = FALSE,
fill = FALSE,
fillgap = -1
)

## Arguments

x |
vector of numerical values. |

y |
vector of numerical values. |

f |
Matrix of numerical values, a matrix f=f(x,y). |

xbreaks |
Vector of values of `x` at the boundaries between bins, calculated using
`pretty` `(x)` if not supplied. |

ybreaks |
Vector of values of `y` at the boundaries between bins, calculated using
`pretty` `(y)` if not supplied. |

flatten |
A logical value indicating whether
the return value also contains equilength
vectors `x` , `y` , `z` and `n` , a flattened
representation of `xmids` , `ymids` , `result` and
`number` . |

fill |
Logical value indicating whether to fill `NA` -value gaps in
the matrix. Gaps will be filled as the average of linear interpolations
across rows and columns. See `fillgap` , which works together with this. |

fillgap |
Integer controlling the size of gap that can be filled
across. If this is negative (as in the default), gaps will be filled
regardless of their size. If it is positive, then gaps exceeding this
number of indices will not be filled. |

## Value

A list with the following elements: the midpoints (renamed as
`x`

and `y`

), the count (`number`

) of `f(x,y)`

values
for `x`

and `y`

values that lie between corresponding breaks,
and the resultant average (`f`

) of `f(x,y)`

, classified by the
`x`

and `y`

breaks.

## See also

## Examples