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

Inconsistent behavior when aggregate by a vector which is not in the data.table when there was a key #762

Closed
colinfang opened this issue Aug 12, 2014 · 0 comments
Assignees
Labels
Milestone

Comments

@colinfang
Copy link

test1 <- data.table(x=1:5, z=5:1)
test2 <- copy(test1)
setkey(test1, z)
y <- c(1,3,2,3,2)

One data.table has a key in it, the other doesn't.

tmp1 <- test1[,list(x=sum(x)), by=y]
key(tmp1)
# [1] "y"
tmp2 <- test2[,list(x=sum(x)), by=y]
key(tmp2)
# NULL

It turns out the key would be replaced by the by term, though it is not sorted at all.

tmp1
#    y x
#1: 1 5
#2: 3 4
#3: 2 3
#4: 3 2
#5: 2 1
tmp2
#    y x
#1: 1 1
#2: 3 6
#3: 2 8

version 1.9.2

@eantonya eantonya added the bug label Aug 12, 2014
@arunsrinivasan arunsrinivasan added this to the v1.9.4 milestone Sep 24, 2014
@arunsrinivasan arunsrinivasan self-assigned this Sep 24, 2014
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

3 participants