Skip to content

uniqueN should also have a “by” argument which by default should check on the key columns #1080

@kevinmistry

Description

@kevinmistry

uniqueN has different behavior than duplicated and unique. Here's an example:

col1 <- c(1,2,3,2,5,3,2)
col2 <- c(0,9,8,9,6,5,4)
example <- data.table(col1,col2)
setkey(example,col1)

example[duplicated(example), .N]
#[1] 3
example[, .N] - uniqueN(example)
#[1] 1
example[, .N] - unique(example)[, .N]
#[1] 3

But when key is set on all columns, they behave the same...

setkey(example,col1,col2)
example[duplicated(example), .N]
#[1] 1
example[, .N] - unique(example)[, .N]
#[1] 1
example[, .N] - unique(example)[, .N]
#[1] 1

It would be nice for uniqueN to have a "by" argument which by default should check on the key columns

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions