Find minimum non-zero value in a column R

2019-05-24 23:54发布

I have this situation in R:

my_minimum <- min(my_data_frame[,my_column_number])

This returns the minimum value. What I want is the minimum non-zero value. I have seen a lot of more complicated situations where people want a vector of the non-zero minimum values but I simply want a single number, the lowest non-zero value that exists in

my_column_number

within

my_data_frame

For context, this is taking place within a for loop that iteratively plots some stuff for each column, and I need to get the non-zero minimum to add to the plot.

标签: r min
3条回答
戒情不戒烟
2楼-- · 2019-05-25 00:11

If you use a vector:

min(myvector[myvector > 0])
查看更多
爷的心禁止访问
3楼-- · 2019-05-25 00:17
min(my_data_frame[,1][which(my_data_frame[,1]>0)])
查看更多
Evening l夕情丶
4楼-- · 2019-05-25 00:33

That should do the trick.

 min(my_data_frame[my_data_frame$my_column_number>0,my_column_number])
查看更多
登录 后发表回答