R function: which.max
which.max returns the position of the element with the maximal value in a vector.
n <- c (31, 47, 18, 9, 25, 19, 62, 32)
pos_max <- which.max(n)
print(pos_max)
# [1] 7
n[pos_max]
# [1] 62
Share this:
- Share on X (Opens in new window) X
- Share on Facebook (Opens in new window) Facebook
- Share on Reddit (Opens in new window) Reddit
- Share on Pinterest (Opens in new window) Pinterest
- Share on X (Opens in new window) X
- Share on LinkedIn (Opens in new window) LinkedIn
- Share on WhatsApp (Opens in new window) WhatsApp
- Share on Tumblr (Opens in new window) Tumblr
- Share on Nextdoor (Opens in new window) Nextdoor
- Share on Mastodon (Opens in new window) Mastodon
- Share on Telegram (Opens in new window) Telegram
