获取R向量中的所有最大值索引 [英] Get all the maximum value indexes in a R vector

查看:31
本文介绍了获取R向量中的所有最大值索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我们在R中有一个向量:

Lets say we have a vector in R :

v <- (2, 3, 4, 5, 5, 5)

我们可以使用max函数轻松找到向量的最大值:

We can easily find the max of the vector using max function :

max(v)

我们如何找到存在最大值的所有索引.有一个函数which.max(v)仅返回第一个索引.有没有一种简单的方法来获取R中具有最大值的所有索引?

How can we find all the indexes where the max value is present. There is function which.max(v) which only returns the first index. Is there an easy way to get all the indexes having max values in R ?

这是一个虚拟的问题,但只是想知道.

Its a dummy question, but just curious to know.

推荐答案

which(v == max(v))怎么样?

这篇关于获取R向量中的所有最大值索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆