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

Comments

Projects
None yet
3 participants
@colinfang
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