R: Extract Unique Rows

Unique {geometry} | R Documentation

## Extract Unique Rows

### Description

‘Unique’ returns a vector, data frame or array like 'x' but with duplicate elements removed.

### Usage

    Unique(X, rows.are.sets = FALSE)

### Arguments

`X` | Numerical matrix.
`rows.are.sets` | If ‘`TRUE`’, rows are treated as sets - i.e., to define uniqueness, the order of the rows does not matter.

### Value

Matrix of the same number of columns as `x`, with the unique rows in `x` sorted according to the columns of `x`. If `rows.are.sets = TRUE` the rows are also sorted.

### Note

‘`Unique`’ is (under circumstances) much quicker than the more generic base function ‘`unique`’.

### Author(s)

Raoul Grasman

### Examples

    # `Unique' is faster than `unique'
    x = matrix(sample(1:(4*8),4*8),ncol=4)
    y = x[sample(1:nrow(x),3000,TRUE), ]
    gc(); system.time(unique(y))
    gc(); system.time(Unique(y))

    #
    z = Unique(y)
    x[matorder(x),]
    z[matorder(z),]

[Package geometry version 0.3-6 Index]