hi I want to to ensure this code I made below is correct. I have my data. I want to group by "id" and "year" summarize and make a new column in which I take the value of the categorical variable "cat" within the grouping WHERE I see the max value of the variable "age". if there is two "cats" with the same age, take the earliest one by arranging id and year.
is the below code correct in achieving my desired goal?
data %>%
group_by(id, year) %>%
arrange(id, year) %>%
summarize(max_cat = cat[which.max(age)])
thank you,