You're looking for which.min()
:
a <- c(1,2,0,3,7,0,0,0)
which.min(a)
# [1] 3
which(a == min(a))
# [1] 3 6 7 8
(As you can see from the above, when several elements are tied for the minimum, which.min()
only returns the index of the first one. You can use the second construct if you instead want the indices of all elements that match the minimum value.)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…