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
{{ message }}
Repository navigation
Unexpected result for max of character variable by group #5331
the difference is whether data.table or base R does the sorting for you.
data.table always sorts in C locale; base sorts in system locale by default (and I'm not sure there an option to toggle with max() to change this on the fly)
you can look at verbose=TRUE in your examples it should be illustrative.
what's your desired outcome? the workaround depends on what you expected.
I don't have a specific desired outcome for whether "alice" or "Bob" is considered to be the maximum. Consistency with base R would be nice, but I can accept that there is more than one reasonable approach.
When I encountered something like this, what I found really confusing was m1 being different in DT[, .(m1 = max(x)), by = "group"] compared to DT[, .(m1 = max(x), m2 = max(tolower(x))), by = "group"], because m1 appears to be defined the same way in both cases, and I wouldn't have expected it to be affected by the inclusion of another column.
agreed there. we have some plan to apply GForce more consistently. the current issue is that one we see an ad-hoc expression, it turns off GForce for the entire query.
understand this can be confusing and is basic exposing an implementation detail. for now your best bet is to remember trying verbose=TRUE to get some insight whenever encountering something like this.
Activity
[-]Unexpected result for max of character variable[/-][+]Unexpected result for max of character variable by group[/+]MichaelChirico commentedon Feb 14, 2022
thanks, this is a great instructive example.
the difference is whether data.table or base R does the sorting for you.
data.table always sorts in C locale; base sorts in system locale by default (and I'm not sure there an option to toggle with max() to change this on the fly)
you can look at verbose=TRUE in your examples it should be illustrative.
what's your desired outcome? the workaround depends on what you expected.
markseeto commentedon Feb 14, 2022
Thanks for the explanation @MichaelChirico.
I don't have a specific desired outcome for whether "alice" or "Bob" is considered to be the maximum. Consistency with base R would be nice, but I can accept that there is more than one reasonable approach.
When I encountered something like this, what I found really confusing was
m1being different inDT[, .(m1 = max(x)), by = "group"]compared toDT[, .(m1 = max(x), m2 = max(tolower(x))), by = "group"], becausem1appears to be defined the same way in both cases, and I wouldn't have expected it to be affected by the inclusion of another column.MichaelChirico commentedon Feb 14, 2022
agreed there. we have some plan to apply GForce more consistently. the current issue is that one we see an ad-hoc expression, it turns off GForce for the entire query.
understand this can be confusing and is basic exposing an implementation detail. for now your best bet is to remember trying verbose=TRUE to get some insight whenever encountering something like this.
MichaelChirico commentedon Feb 14, 2022
if you want consistency, I believe you can set Sys.setenv(LC_ALL="C")
markseeto commentedon Feb 14, 2022
Thanks for your replies @MichaelChirico.
I had tried verbose=TRUE but still wasn't sure about the reason until I read your explanation.