I have a similar problem as outlined in this question. The problem is that I have more than 200 columns, so I can't list them all as in this code:
df %>%
rowwise %>%
mutate(Max = names(.)[which.max(c(x, y, z))]) %>%
ungroup
I have tried using this code but it is giving the max of all my columns and I just need the max of columns 3 to 223. Columns 1 and 2 are ID and year and I need them.
df %>%
rowwise() %>%
mutate(Max = names(.)[which.max(c_across(3:223))]) %>%
ungroup()
All my columns have different names so I can't use
mutate(Max = names(.)[which.max(c_across(starts_with("X")))])
How can I find the name of the column with the maximum value per row of a dataset with around 200 columns without listing all of the 200 columns' names?