Skip to content
Prev 304407 / 398503 Next

return first index for each unique value in a vector

Sheesh!

I would have thought that someone would have noticed that on the
?unique Help page there is a link to ?duplicated, which gives a
_logical_ vector of the duplicates. From this, everything else can be
quickly derived -- and packaged in a simple Matlab like function, if
you insist on that. e.g.

unik <- !duplicated(A)  ## logical vector of unique values
seq_along(A)[unik]  ## indices
A[unik] ## the values

If you want the indices in increasing order, see ?order

-- Bert

On Tue, Aug 28, 2012 at 3:32 PM, R. Michael Weylandt
<michael.weylandt at gmail.com> wrote: