which.max ties method in R
问题 which.max and which.min will return the smallest index of the max or min value if there are ties. Is there a way around this so that the largest index is returned without affecting the efficiency of the function? max.col has this exact functionality, but I am dealing with a vector not a matrix. 回答1: You could do like this: x<-c(1,2,1,4,3,4) #identical to which.max, except returns all indices with max which(x==max(x)) [1] 4 6 z<-which(x==max(x)) z[length(z)] [1] 6 #or with tail tail(which(x=