Usage

Arguments

a vector of the same length as x, whose subset
of values for each unique level of x determines the
eventual order of that level.

FUN

a function whose first argument is a vector and
returns a scalar, to be applied to each subset of X
determined by the levels of x.

...

optional: extra arguments supplied to FUN

order

logical, whether return value will be an ordered factor
rather than a factor.

Value

A factor or an ordered factor (depending on the value of
order), with the order of the levels determined by
FUN applied to X grouped by x. The
levels are ordered such that the values returned by FUN
are in increasing order.
Additionally, the values of FUN applied to the subsets of
X (in the original order of the levels of x) is returned
as the "scores" attribute.