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

X[Y, .N] when there are some rows with no matches #963

Closed
arunsrinivasan opened this issue Nov 18, 2014 · 0 comments
Closed

X[Y, .N] when there are some rows with no matches #963

arunsrinivasan opened this issue Nov 18, 2014 · 0 comments
Assignees
Labels
Milestone

Comments

@arunsrinivasan
Copy link
Member

Came across this when writing an answer to this SO post. Most definitely a bug.

require(data.table) ## 1.9.5
X = data.table(x=c(1,1,1,2,2), y=1:5, key="x")
Y = data.table(x=2:5, y=letters[1:4], key="x")
X[Y]
#    x  y i.y
#1: 2  4   a
#2: 2  5   a
#3: 3 NA   b
#4: 4 NA   c
#5: 5 NA   d
X[Y, .N]
# [1] 2
X[Y, .N, nomatch=0L]
# [1] 2

The first result should be 5, since the count is happening after performing the join. For example, sum(y) works as intended.

X[Y, sum(y)] # [1] NA - correct result
X[Y, sum(y, na.rm=TRUE)] # correct result
@arunsrinivasan arunsrinivasan self-assigned this Nov 18, 2014
@arunsrinivasan arunsrinivasan added this to the v1.9.6 milestone Nov 18, 2014
arunsrinivasan added a commit that referenced this issue Jan 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant