# How to find the smallest number in an R data frame column excluding values zero or less?

To find the smallest number in an R data frame column excluding values zero or less, we can use min function along with subsetting of values greater than 0 through single square brackets.

For example, if we have a data frame called df that contains a column say X then the smallest number excluding values zero or less can be found by using the below command −

## Output

If you execute all the above given snippets as a single program, it generates the following output −

[1] 0.1048411


## Example 2

Following snippet creates a sample data frame −

y<-rpois(20,1)
df2<-data.frame(y)
df2

The following dataframe is created −

   y
1  0
2  1
3  0
4  1
5  1
6  0
7  0
8  2
9  2
10 1
11 3
12 1
13 1
14 0
15 0
16 1
17 2
18 3
19 2
20 1

To find the smallest values after excluding values less than 0 in y, add the following code to the above snippet −

y<-rpois(20,1)
df2<-data.frame(y)

## Output

If you execute all the above given snippets as a single program, it generates the following output −

[1] 0.1325154