Unique or Duplicated Values in a Vector

DESCRIPTION:
Returns the values of the input without any repetition, or a logical vector denoting which elements duplicate previous elements.

USAGE:
unique(x, incomparables = F)
duplicated(x, incomparables = F)

REQUIRED ARGUMENTS:
x:
a vector. Missing values and Infs are allowed.

OPTIONAL ARGUMENTS:
incomparables:
a vector of values that cannot be compared, each value in x that matches a value in this vector is considered unique. If incomparables=FALSE all values can be compared.

VALUE:
unique returns an object like x but with no duplicate values. The values will be in the same order as x except that repeated values will be deleted.

duplicated returns a logical vector the same length as x that tells for each element of x whether that value has appeared before in x.


DETAILS:
By default, any value is considered able to be duplicated. The incomparables argument allows you to select values that will always be considered unique. (The values TRUE and FALSE are always able to be duplicated.)

The duplicated function is generic and hence unique is effectively generic since it is based on duplicated (and [). Currently there are no methods for duplicated.


WARNING:
When x is numeric, apparently equal values may not be considered equal due to numerical imprecision.

NOTE:
Function unique is actually implemented as x[!duplicated(x,incomparables)].

SEE ALSO:
sort , rep , category .

EXAMPLES:
sort(unique(names))  # sorted list of names with no duplicates

unique(x[duplicated(x)]) # values that occur at least twice

unique(x, incomp=c(1/0,-1/0)) # make infinities non-unique