DT = data.table(a = rep(4:1, 1:4), v = rnorm(10))
setkey(DT, a)
setorder(DT, a, v)
key(DT)
# NULL
Obviously DT is still sorted by a after setorder; that's why the second setkey here only runs setattr (btw, we should report this is happening if verbose = TRUE)
DT = data.table(a = rep(4:1, 1:4), v = rnorm(10))
setkey(DT, a, v)
setkey(DT, a, verbose = TRUE)
The note in the code is:
if forderv is not 0-length, it means order has changed. So, set key to NULL, else retain key.
So I guess it could be a conceptual question -- do we reset the key if the order has changed but the table is still sorted by the stated key?
This is particularly odd if I want to sort the last column in decreasing order. Is there any have DT keyed by a but guaranteed v is in decreasing order within a?
Obviously
DTis still sorted byaaftersetorder; that's why the secondsetkeyhere only runssetattr(btw, we should report this is happening ifverbose = TRUE)The note in the code is:
So I guess it could be a conceptual question -- do we reset the key if the order has changed but the table is still sorted by the stated key?
This is particularly odd if I want to sort the last column in decreasing order. Is there any have
DTkeyed byabut guaranteedvis in decreasing order withina?