unique(x, incomparables = FALSE, ...) ## Default S3 method: unique(x, incomparables = FALSE, fromLast = FALSE, nmax = NA, ...) ## S3 method for class 'data.frame': unique(x, incomparables = FALSE, fromLast = FALSE, ...) ## S3 method for class 'matrix': unique(x, incomparables = FALSE , MARGIN = 1, fromLast = FALSE, ...) ## S3 method for class 'array': unique(x, incomparables = FALSE , MARGIN = 1, fromLast = FALSE, ...) ## S3 method for class 'POSIXlt': unique(x, incomparables = FALSE, ...)
| x | a vector. Missing values (NAs) and Infs are allowed. Some methods handle other objects, such as data frames, matrices, or arrays. | 
| 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 (the default) or incomparables=NULL, all values can be compared. | 
| fromLast | a logical flag. If TRUE, compares the duplicated values from the last to the head. If FALSE (the default), compares the duplicated values from the head to the last. | 
| nmax | a positive integer or NA. If a positive integer is given then it is considered an error if x contains more than nmax unique values. | 
| MARGIN | a single integer; the array margin to be held. | 
| ... | arguments for particular methods. Many of the methods will call the default method and those will pass a possible nmax argument to it. | 
Names <- c("Mike", "Al", "Larry", "Al", "Al", "Zeus", "Mike", "Larry")
sort(unique(Names))  # sorted list of Names with no duplicates
x <- c(-1/0, -1/0, -2, -2, 2, 2, 1/0, 3/0)
unique(x, incomp=c(1/0, -1/0))  # treat all infinities as unique
## POSIXlt
x <- as.POSIXlt("1970-01-01")
unique(c(x, x+1, x, x+1, NA))
hasLotsOfUniqueValues <- function(x, nmax) {
    # for very long x, unique(x) can use a lot of memory.
    # This function avoids that.
    tryCatch({unique(x, nmax=nmax); FALSE}, error=function(e)TRUE)
}
hasLotsOfUniqueValues(seq_len(10000000), nmax=100)
hasLotsOfUniqueValues(seq_len(75), nmax=100)