How to identify coordinates in R

前端 未结 3 1509
[愿得一人]
[愿得一人] 2021-01-17 08:25

I would like to identify which coordinate of my vector gives me the greatest value. For a simple example suppose that:

x <- c(10,22,20,18,5)
3条回答
  •  误落风尘
    2021-01-17 08:47

    which.max is your friend as pointed out by @Hong Ooi

    > x <- c(10,22,20,18,5)
    > which.max(x)
    [1] 2
    

    Another (not optimal way) is a combination of which and max.

    > which(x==max(x))
    [1] 2
    

提交回复
热议问题