``` 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