You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But x[order(., decreasing = TRUE)] is also optimized. Using the example from ?setorder:
set.seed(45L)
DT = data.table(A=sample(3, 10, TRUE),
B=sample(letters[1:3], 10, TRUE), C=sample(10))
DT[order(C, decreasing = TRUE), verbose = TRUE]
# order optimisation is on, i changed from 'order(...)' to 'forder(DT, ...)'.
# A B C
# 1: 1 b 10
# 2: 2 a 9
# 3: 2 b 8
# 4: 1 a 7
# 5: 2 b 6
# 6: 1 a 5
# 7: 1 c 4
# 8: 1 c 3
# 9: 2 b 2
# 10: 1 b 1
Thanks for sharing Michael, I'm wondering though if it is as simple as mentioning the forder-applicable case for a descending sort operation in that block of comments:
# optimised to use data.table's internal fast order
# x[order(., na.last = TRUE)]
# x[order(., decreasing = TRUE)]
or did you want me to add more to setorder.Rd such as writing on the performance gains of base R's order vs forder, or investigate for notes on better speedups?
(I'm not sure what more to add apart from including the case with the decreasing = TRUE argument, especially since for the na.last = TRUE argument too there isn't a section explaining more about the optimized order operation for placing all ordered non-NA values before NAs in the sorted data)
Activity
MichaelChirico commentedon Mar 29, 2024
hey @Anirban166, given #6018 I thought this might be a similar PR you could help with, feel free to re-assign :)
Anirban166 commentedon Mar 29, 2024
Thanks for sharing Michael, I'm wondering though if it is as simple as mentioning the
forder-applicable case for a descending sort operation in that block of comments:or did you want me to add more to setorder.Rd such as writing on the performance gains of base R's order vs
forder, or investigate for notes on better speedups?(I'm not sure what more to add apart from including the case with the
decreasing = TRUEargument, especially since for thena.last = TRUEargument too there isn't a section explaining more about the optimizedorderoperation for placing all ordered non-NA values before NAs in the sorted data)MichaelChirico commentedon Mar 30, 2024
Yes, I think the simple change is enough.