-
Notifications
You must be signed in to change notification settings - Fork 370
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
Add groupindices
as special source argument in minilanguage
#2683
Comments
I would assume you would want |
Regarding |
OK, now I get what you wanted. Adding this has been discussed in the past here: #2556 (comment). |
I'm actually googling for how to do this right now in Stata and coming up short (so far). So definitely in favor of this feature. |
To be clear. We currently have this feature. Just do:
and now you can use this column freely in all further computations. The point here is to avoid allocation of this extra column if I understand the request correctly. |
No, I don't think that's the request. I think the request is to special case the function, exactly like But I could be mistaken. My current use case is I have many variables and want to make a unique group number for each group. Then I can just work with that group number instead of keeping track of all the variables I need to group by all the time. So the point is to allocate a new column for the group indices. My understanding is that this was also @jkrumbiegel 's request. |
But I have just shown above how to do it now.
Yes, but it is only useful if you do not want to add this column to a data frame. If you want to add it then just do something like:
|
Yeah, I think OP is just asking for a convenience function to make it easier in piping. |
The example above uses only three rows and three groups, so the fact that one can assign the output of I do want this available in the context of piping and the |
I think one point of confusion is that there are two different behaviors we could be asking for.
This is exactly how
We don't currently have this behavior for anything. So it would be a big change in the mini-language to add (I've discussed adding more complicated inputs as I wouldn't mind seeing option 1. get added. |
I assumed we were discussing option 2 in this issue. Indeed we could consider also adding option 1, which would be rather expressed as:
|
Fixed with #3001 |
I often want to know a group's index in
transform
statements, especially when I have sorted while grouping and need to continue doing something with this order. There is currently no easy way to access the group indices.data.table has the special variable
.GRP
for this purpose. There's also.NGRP
which returns the number of groups, which could also be useful.I'm thinking that one could elevate
groupindices
to the same status asnrow
so that one can write this:The text was updated successfully, but these errors were encountered: