在每一行中查找最小正值(不包括0) [英] Find Minimum positive value in each row (exclude 0)

查看:90
本文介绍了在每一行中查找最小正值(不包括0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在处理矩阵,我想在每一行中找到最低的正值.

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

使用apply(my.matrix,1,min)无效,因为输出始终为0 ...

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

是否可以找到除0以外的最低值?

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

推荐答案

您可以使用匿名函数来做到这一点.

You can do this with an anonymous function.

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

这篇关于在每一行中查找最小正值(不包括0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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