R Error: Non-numeric Argument to Binary Operator | How to Fix (Example)
Please note that this page illustrates the error message returned by Base R. In case you are looking for the error message “Error in max.item – min.item : non-numeric argument to binary operator” returned by the alpha function of the psych package, you may have a look here.
Table of contents:
Let’s dive right into the example!
Example: Reproducing & Fixing the Error Message: non-numeric argument to binary operator
In this Example, I’ll explain how to reproduce and fix the error message “non-numeric argument to binary operator”. First, let’s create an example that reproduces the error:
5 * "three" # Trying to use character string in equation # Error in 5 * "three" : non-numeric argument to binary operator
As you can see based on the previous R code, we have tried to use a character string in an equation (i.e. “three”). Unfortunately, this is not possible in the R programming language.
If we want to solve this problem, we need to replace the character string by a numeric value (i.e. 3). Let’s do that:
5 * 3 # Proper equation # 15
As you can see, the RStudio console is not returning the error anymore. Instead it shows the result of our equation.
Video & Further Resources
Would you like to learn more about error messages in R? Then you might have a look at the following video of my YouTube channel. I explain the R programming code of this page in the video instruction:
Besides the video, you could have a look at the other articles of my website.
Summary: In this article you learned how to handle the error non-numeric argument to binary operator in the R programming language. Tell me about it in the comments, in case you have additional questions.