Extracts the unique values of x, applies fn to those unique
values, and maps the results back to the original vector. This avoids
redundant computation when x contains many repeated values.
Value
A vector of the same length as x, holding the value of
fn for each element (computed via unique-value lookup). The result
takes its class from the value fn returns.
Details
The function calls fn exactly once, on the vector of unique values of
x. It does not call fn once per element. It does not call
fn once per unique value either. fn MUST therefore be
vectorised. It receives the whole vector of unique values in a single call.
This can dramatically speed up computation when there is a lot of data and
a limited number of unique values. The work fn does scales with the
number of unique values, not with the length of x.
See also
vignette("csutil", package = "csutil"), which times this
function against a direct call to format().
