Matrix Multiplication Error in R: non-conformable arguments (2 Examples)


In this article, I’ll illustrate how to deal with the error message “non-conformable arguments” in R when performing matrix multiplication.

Table of contents:

Let’s do this…


Introduction of Example Data

Have a look at the exemplifying data below:

m1 <- matrix(2)                 # Create first data object
m1                              # Print first data object


table 1 matrix error non conformable arguments r


Table 1 illustrates our first data object: A matrix containing only one value.

m2 <- matrix(1:15, nrow = 5)    # Create second data object
m2                              # Print second data object


table 2 matrix error non conformable arguments r


Table 2 shows the second data object: A matrix with five rows and three columns.


Example 1: Reproduce the Error Message – non-conformable arguments

In this example, I’ll explain how to reproduce the error message “non-conformable arguments” in R.

Let’s assume that we want to multiply our two data objects. Then, we might try to execute the following R code:

m1 %*% m2                       # Trying to multiply data objects
# Error in m1 %*% m2 : non-conformable arguments

As you can see, the error message “non-conformable arguments” has been returned to the RStudio console.

The reason for this is that our first data object m1 is a 1×1 matrix.

Let’s see how we can solve this problem…


Example 2: Fix the Error Message – non-conformable arguments

This example explains how to handle the error message “non-conformable arguments”.

To do this, we have to convert our 1×1 matrix to a vector using the as.vector function:

as.vector(m1) * m2              # Converting m1 to vector


table 3 matrix error non conformable arguments r


Table 3 illustrates the result of the previous R syntax.


Video & Further Resources

In case you need more info on the R programming code of this tutorial, you might want to watch the following video of my YouTube channel. In the video, I’m explaining the topics of this tutorial in R:


The YouTube video will be added soon.


Furthermore, you might want to have a look at the other R tutorials on my website.


Summary: At this point you should have learned how to avoid the error “non-conformable arguments” in R programming. If you have additional questions, let me know in the comments section below.


Subscribe to the Statistics Globe Newsletter

Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.