Find Minimum positive value in each row (exclude 0

2019-07-28 06:32发布

I am currently working with a matrix and I want to find the lowest positive value in each row.

Using apply(my.matrix,1,min) won't work since the output will always be 0...

Is there a way to find the lowest value excluding 0?

标签: r min
2条回答
我欲成王,谁敢阻挡
2楼-- · 2019-07-28 06:57

This variation on your approach works for me:

apply(my.matrix, 1, FUN=function(x) {min(x>0)})
查看更多
祖国的老花朵
3楼-- · 2019-07-28 07:02

You can do this with an anonymous function.

apply(my.matrix, 1, FUN = function(x) {min(x[x > 0])})
查看更多
登录 后发表回答