# R Warning message in min & max: no non-missing arguments; returning Inf

This article explains how to **debug the warning message in min and max – “no non-missing arguments; returning Inf”** in the R programming language.

The tutorial is structured as follows:

Let’s jump right to the examples…

## Example 1: Reproduce the Warning Message in min & max – no non-missing arguments; returning Inf

In Example 1, I’ll show how to replicate the warning message in min and max – “no non-missing arguments; returning Inf” in the R programming language.

For this, we first have to create some example data:

x1 <- numeric(0) # Create empty vector |

x1 <- numeric(0) # Create empty vector

As you can see, our example data is an empty vector. Let’s try to apply the min and max functions to this vector.

min(x1) # Apply min to empty vector # [1] Inf # Warning message: # In min(x1) : no non-missing arguments to min; returning Inf |

min(x1) # Apply min to empty vector # [1] Inf # Warning message: # In min(x1) : no non-missing arguments to min; returning Inf

The min function returns the value Inf (i.e. infinity)…

max(x1) # Apply max to empty vector # [1] -Inf # Warning message: # In max(x1) : no non-missing arguments to max; returning -Inf |

max(x1) # Apply max to empty vector # [1] -Inf # Warning message: # In max(x1) : no non-missing arguments to max; returning -Inf

…and the max function returns the value _Inf (i.e. negative infinity).

The reason for this is that we have tried to perform a mathematical operation based on an empty data object.

How can we solve this problem in R?

## Example 2: Fix the Warning Message in min & max – no non-missing arguments; returning Inf

Example 2 illustrates how to deal with the warning in min and max – “no non-missing arguments; returning Inf”.

First, let’s create a vector containing numeric or integer values:

x2 <- 1:5 # Create non-empty vector |

x2 <- 1:5 # Create non-empty vector

If we now apply the min and max functions, the RStudio console returns valid results. First, let’s use the min function…

min(x2) # Apply min to non-empty vector # [1] 1 |

min(x2) # Apply min to non-empty vector # [1] 1

…and then the max function:

max(x2) # Apply max to non-empty vector # [1] 5 |

max(x2) # Apply max to non-empty vector # [1] 5

Looks good!

## Video & Further Resources

Have a look at the following video of my YouTube channel. In the video, I’m explaining the R programming code of this article in R:

*The YouTube video will be added soon.*

In addition, you might read the other articles of my homepage. I have published several tutorials already:

- message() vs. warning() vs. stop() Functions
- Warning Message in read.table: Incomplete Final Line Found by readTableHeader
- max and min Functions in R
- Warning Message – In Ops.factor : not meaningful for factors
- Dealing with Warnings & Errors in R
- R Programming Examples

Summary: You have learned in this tutorial how to **handle the warning message in min and max – “no non-missing arguments; returning Inf”** in the R programming language. Don’t hesitate to let me know in the comments section, if you have further questions and/or comments.