duplicated

0th

Percentile

Determine Duplicate Rows

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.

Keywords
data
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.
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.

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.

See Also

data.table, duplicated, unique

Aliases
  • duplicated.data.table
  • unique.data.table
Examples
(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)
Documentation reproduced from package data.table, version 1.6.5, License: GPL

Community examples

Looks like there are no examples yet.