-
Notifications
You must be signed in to change notification settings - Fork 1k
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
New function to evaluate any in i grouped by keyby or by #6661
Comments
These forms are equivalent
The last one is particularly close to your use case. Note the .(), if you omit it , you'll obtain zero for the sum of id's with no A's in Trt |
IIUC #788 solves this: DT[, by=Id, having=any(Trt=='A'), sum(Dur)] In current code, slightly more canonical (readable?) than the above suggestion with .SD is DT[, if(any(Trt=='A')) sum(Dur), by=Id] |
Another way, likely more useful when
The (current) approach suggested by @MichaelChirico would fail if there is a group (in
|
I think we can close this request. Learning new functions feels less optimal then using just base R style |
Hi
Would it be possible to add a function that evaluates any() in i by each group given by keyby or by. So instead of
the final line would be replaced by
DT(anyby(Trt=="A"),sum(Dur),by=Id)
The text was updated successfully, but these errors were encountered: