max - Choosing highest number in vector and knowing its position in R -
i have vector in r:
y=c(-29.900900, 5.728916, 35.234331, 11.854811, 61.309519, 50.432798, -27.654741, 21.413622, -10.805339, -37.504199)
i select highest number using example max(y)
.
then gives me 61.309519
.
but in addition know position i.e. 5th
element in vector.
is there way this? i'm ok using other data formats eg. matrix
or data.frame
which.max()
function return index of first maximum element. might important when have more 1 maximum in vector.
Comments
Post a Comment