Fairly often I have a need to get the Ordering of an expression but with recognition of duplicates. For example:
Ordering[{0, 4, 1, 1, 2}]
{1, 3, 4, 5, 2}
but with duplicates such as 3, 4 marked, i.e.:
{{1}, {3, 4}, {5}, {2}}
I have been using a decorate-and-sort followed by SplitBy and Part:
{0, 4, 1, 1, 2} //
SplitBy[Sort[{#, Range@Length@#}\[Transpose]], First][[All, All, 2]] &
{{1}, {3, 4}, {5}, {2}}
Is there a better way?
