Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R-Forge #2377] Change keyby to run j by group in sorted order, too, rather than key afterwards. #606

Closed
arunsrinivasan opened this issue Jun 8, 2014 · 1 comment

Comments

@arunsrinivasan
Copy link
Member

Submitted by: Matt Dowle; Assigned to: Nobody; R-Forge link

This option would only be useful where j depends on some value from the previous group; as demonstrated here :

http://stackoverflow.com/a/8833899/403310

If you mix up the order of DT there, so it isn't sorted by TreatmentID:
set.seed(10)
DT2 = DT[sample(1:24)]

then

r=0; DT2[,{r<<-min(Rank[Rank>r]); .SD[Rank==r]}, keyby=TreatmentID]

returns slightly different (but correct) results because Rank 3 and 4 both appear in both IDs 2 and 3.

Changing by to keyby, returns the same result, just ordered differently.

Perhaps keyby should run the groups in the sorted order, instead. Or perhaps that should be optional.

To repeat the begining of this FR, it only makes a difference if each group depends on the previous group result, as in that S.O. answer.

@mattdowle
Copy link
Member

a398972 implements this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants