Learn R Programming

geometry (version 0.5.0)

Unique: 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)

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.

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.

Author

Raoul Grasman

Examples

Run this code

# `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),]

Run the code above in your browser using DataLab