Find Minimum positive value in each row (exclude 0)

谁说我不能喝 提交于 2019-12-11 07:43:49

问题


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?


回答1:


You can do this with an anonymous function.

apply(my.matrix, 1, FUN = function(x) {min(x[x > 0])})



回答2:


This variation on your approach works for me:

apply(my.matrix, 1, FUN=function(x) {min(x>0)})


来源:https://stackoverflow.com/questions/10717831/find-minimum-positive-value-in-each-row-exclude-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!