Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kevinmistry opened this issue Mar 13, 2015 · 0 comments
Assignees
Milestone

Comments

@kevinmistry
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants