median(x, na.rm = F, weights = NULL)
bdNumeric
.
Missing values (NA) are allowed.
x
for computing weighted
median (see below). Does not have to be normalized to sum to 1.
If argument
weights
is provided,
x
is sorted and
weights
are normalized to sum to 1. The median is then
the value of
x
corresponding to the first cum-summed weight greater
than or equal to .5. In case a cum-summed weight is equal to .5, the
median is the average of the value of
x
corresponding to that weight
and the value of
x
corresponding to the first cumsumed weight
strictly greater than .5 (there may be intervening zero-valued
weights, which are ignored).
If
x
contains any
NA
s, the result will be
NA
unless
na.rm=TRUE
.
For long vectors or
bdVectors
, using
quantile(x, .5)
rather than
median(x)
is significantly faster, because
quantile
uses a partial sort, while
median
uses a sort.
Note that
quantile(x, .5, weights = weights)
gives a different
answer than
median(x, weights = weights)
.
Also,
quantile
uses single precision.
algebra <- testscores[,3] # create sample object of algebra testscores median(algebra) # median of scores apply(testscores, 2, median) # vector of the medians of the columns # in testscores data set