data.table (version 1.4.1)

duplicated: Determine Duplicate Rows

Description

duplicated determines which rows of a data table have duplicate keys of rows with smaller subscripts, and returns a logical vector indicating which rows are duplicates by key.

unique returns a data table with duplicated rows (by key) removed.

Usage

## S3 method for class 'data.table':
duplicated(x, ...)

## S3 method for class 'data.table': unique(x, ...)

Arguments

x
A data.table.
...
Not used at this time.

Value

  • duplicated returns a logical vector of length nrow(x) indicating which rows are duplicates by key.

    unique returns a data table with duplicated rows (by key) removed.

Details

Because data.tables are sorted by key, tests for duplication are relatively quick.

Note that only keys are checked for duplication. Unkeyed columns are not checked.

See Also

data.table, duplicated, unique

Examples

Run this code
(dt <- data.table(A = rep(1:3, each=4), B = rep(1:4, each=3), C = rep(1:2, 6), key = "A,B"))
    duplicated(dt)
    unique(dt)

Run the code above in your browser using DataCamp Workspace