找出R中最小非负值的索引

Nav*_*swi 2 r data-manipulation

假设数字向量x <- c(-3,2,1,-2, 4,-1,-5)
Min非负值in x1索引/位置/答案应该是3.
我们怎样才能使用任何功能呢?

(注意:which.min在上面的例子中,函数给出的答案/索引7是最小的(但不是非负的))

Sve*_*ein 8

您可以使用

which.max(1 / x)
# [1] 3
Run Code Online (Sandbox Code Playgroud)