-
Let's say I want to get the year and the cases where the max number cases happened in table1 In R there's This doesn't work:
|
Beta Was this translation helpful? Give feedback.
Answered by
jheer
Sep 1, 2022
Replies: 1 comment 4 replies
-
One way to do this is to use aq.table({
g: [1, 1, 1, 1, 2, 2, 2, 2],
v: [1, 1, 2, 2, 3, 3, 4, 4],
y: [1, 2, 3, 4, 1, 2, 3, 4]
})
.groupby('g')
.filter(d => op.max(d.v) === d.v) // remove rows that do not contain max(v)
.filter(d => op.row_number() === 1) // retain only the first row in each group
.view() |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
jheer
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One way to do this is to use
filter
to reduce the table to just the max (or min) values. Note that a minimum or maximum value may appear more than once. If desired, you can then use anotherfilter
to limit the result to a single max/min per group.