# R Error in max.item – min.item : non-numeric argument to binary operator (psych Package)

In this R programming tutorial you’ll learn how to solve the error message “Error in max.item – min.item : non-numeric argument to binary operator” created by the alpha function of the psych package.

Please note that this tutorial is discussing the error message returned by the psych package. In case you are looking for the error message “non-numeric argument to binary operator” returned by the basic installation or the R programming language, you may check out this tutorial.

Let’s start right away…

## Example 1: Reproduce the Error in max.item – min.item : non-numeric argument to binary operator

This example shows how to replicate the error message “Error in max.item – min.item : non-numeric argument to binary operator” that is returned by the alpha function of the psych package.

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

```set.seed(635784)                             # Create random example data
data_fac <- data.frame(res_1 = sample(1:5, 100, replace = TRUE),
res_2 = as.factor(sample(1:5, 100, replace = TRUE))) As shown in Table 1, we have created a data frame with two columns by executing the previous syntax.

Furthermore, we need to install and load the psych package:

```install.packages("psych")                    # Install & load psych package
library("psych")```

Now, we might try to apply the alpha function of the psych package to our data frame as shown below:

```psych::alpha(data_fac)                       # Apply alpha function
# Error in max.item - min.item : non-numeric argument to binary operator```

However, as you can see the RStudio console returns the error message “Error in max.item – min.item : non-numeric argument to binary operator”.

The reason for this is that one of the columns in our data frame has the factor class instead of the numeric class.

Let’s solve this problem!

## Example 2: Fix the Error in max.item – min.item : non-numeric argument to binary operator

In Example 2, I’ll illustrate how to handle the “Error in max.item – min.item : non-numeric argument to binary operator”.

For this, we first have to convert all columns in our data frame to the numeric class. For this, we can use the apply, as.numeric, and as.character functions as shown below:

```data_num <- as.data.frame(apply(data_fac,    # Convert all columns to numeric
2,
function(x) as.numeric(as.character(x))))```

Let’s check the classes of our new data frame:

`sapply(data_num, class)                      # Check classes of all columns`

As you can see, all our variables are numeric.

Now, we can apply the alpha function of the psych package as we already did before:

```psych::alpha(data_num)                       # Apply alpha function
# Reliability analysis
# Call: psych::alpha(x = data_num)
#
#   raw_alpha std.alpha G6(smc) average_r  S/N  ase mean   sd median_r
#       0.11      0.11   0.057     0.057 0.12 0.18    3 0.99    0.057
#
#  lower alpha upper     95% confidence boundaries
# -0.24 0.11 0.46
#
#  Reliability if an item is dropped:
#       raw_alpha std.alpha G6(smc) average_r  S/N alpha se var.r med.r
# res_1     0.052     0.057  0.0032     0.057 0.06       NA     0 0.057
# res_2     0.062     0.057  0.0032     0.057 0.06       NA     0 0.057
#
#  Item statistics
#         n raw.r std.r r.cor r.drop mean  sd
# res_1 100  0.70  0.73  0.17  0.057  3.2 1.3
# res_2 100  0.76  0.73  0.17  0.057  2.9 1.4
#
# Non missing response frequency for each item
#          1    2    3    4    5 miss
# res_1 0.11 0.25 0.18 0.27 0.19    0
# res_2 0.24 0.20 0.19 0.20 0.17    0```

The result is returned as expected without showing any error messages.

## Video & Further Resources

If you need further explanations on the R programming code of the present article, I recommend watching the following video on my YouTube channel. I’m showing the R programming codes of this tutorial in the video:

Furthermore, you may have a look at some of the other articles on https://statisticsglobe.com/:

This article has demonstrated how to avoid the “Error in max.item – min.item : non-numeric argument to binary operator” in the R programming language. If you have additional questions, tell me about it in the comments section below.

Subscribe to the Statistics Globe Newsletter