R: returning the minimum positive number

r

Solution

This function would work:

minpositive = function(x) min(x[x > 0])

For example:

dfcount  <- data.frame(A=c(1,2,3,4,-5,-6,-7))
minpositive(dfcount)
# 1

Problem

I have a dataframe with positive and negative numbers. What I need to return is the smallest positive number. Is there a function that does this? ``` dfcount <- data.frame(A=c(1,2,3,4,-5,-6,-7)) ``` ie minpositive(dfcount) returns 1 and not -7 Thank you for your help

Original source