I am looking for a way to get the second(third, fourth etc.) smallest/ largest element of a list in R. Using which.min / which.max I came up with the following solution for the second largest element:
test <- c(9,1,3,5,2,4,10)
(test[-which.max(test)])[which.max(test[-which.max(test)])]]
However, this is ugly and does not really scale up. Is there a better way to get the x smallest/largest element/value of a list?