| binApply1D {oce} | R Documentation |
Apply a Function to Vector Data
Description
The function FUN is applied to f in bins specified by
xbreaks. The division of data into bins is done with cut().
Usage
binApply1D(x, f, xbreaks, FUN, include.lowest = FALSE, ...)
Arguments
x |
a vector of numerical values. |
f |
a vector of data to which |
xbreaks |
optional vector holding values of x at the boundaries between bins.
If this is not given, it is computed by calling |
FUN |
function that is applied to the |
include.lowest |
logical value indicating whether to include
|
... |
optional arguments to pass to |
Details
By default, the sub-intervals defined by the xbreaks argument are open
on the left and closed on the right, to match the behaviour
of cut(). An open interval does not include points on
the boundary, and so any x values that exactly match
the first breaks value will not be counted. To include
such points in the calculation, set include.lowest to TRUE.
Value
A list with the following elements: xbreaks as
used, xmids (the mid-points between those breaks) and
result (the result of applying FUN to the f values
in the designated bins).
Author(s)
Dan Kelley
See Also
Other bin-related functions:
binApply2D(),
binAverage(),
binCount1D(),
binCount2D(),
binMean1D(),
binMean2D()
Examples
library(oce)
# salinity profile (black) with 1-dbar bin means (red)
data(ctd)
plotProfile(ctd, "salinity")
p <- ctd[["pressure"]]
S <- ctd[["salinity"]]
pbreaks <- seq(0, max(p), 1)
binned <- binApply1D(p, S, pbreaks, mean)
lines(binned$result, binned$xmids, lwd = 2, col = rgb(1, 0, 0, 0.9))