I have a large dataset that essentially looks like so:
ex <- data.frame(member = c(rep(1234,5)),
caseid = c(72,74,78,72,78),
code = c(2270,2508,2270,2134,2984),
pay = c(90,120,40,60,200))
I would like to find a way to replace the value in code with the code value corresponding to the row with the highest pay, while being grouped by the caseid column. The output that I would like would be like this:
ex1 <- data.frame(member = c(rep(1234,5)),
caseid = c(72,74,78,72,78),
code = c(2270,2508,2984,2270,2984),
pay = c(90,120,40,60,200))
I am trying to update the code column based on the pay column. So since row 1 has the highest pay of 90, replace row 4 with code 2270
Is there a way I could do this using data.table or tidyverse? The actual dataset has multiple members with different caseids so I would like something that could also group by member id to apply these changes by each member as well. Thanks in advance!