Suppose I have the following vector
test <- c("x1" = 0.1, "x2" = 0.3, "x3" = 0.4,
"y1" = 0.1, "y2" = 0.5, "y3" = 0.4,
"z1" = 0.5, "z2" = 0.3, "z3" = 0.4)
test
# x1 x2 x3 y1 y2 y3 z1 z2 z3
# 0.1 0.3 0.4 0.1 0.5 0.4 0.5 0.3 0.4
I want to find the vector element with the highest value, grouped per letter. So in this case, I want the output to be "x3", "y2", "z1". The tricky thing is that I do not know in advance how many different letter groups there will be, nor how many numbers there will be per letter. Hence, I would need a simple yet flexible code that does not need a pre-specified grouping.
Any suggestions on which functions to use?