Warning Message in R: longer object length not multiple of shorter object

 

In this article you’ll learn how to deal with the warning message “longer object length is not a multiple of shorter object length” in R programming.

The post looks as follows:

So now the part you have been waiting for – the exemplifying R code.

 

Example 1: Reproduce the Warning – longer object length is not a multiple of shorter object length

In this example, I’ll explain how to replicate the warning message “longer object length is not a multiple of shorter object length” in R. Consider the following R syntax:

1:5 + 1:6                     # Using two vectors with different length
# [1]  2  4  6  8 10  7
# Warning message:
# In 1:5 + 1:6 :
#   longer object length is not a multiple of shorter object length

As you can see, the RStudio console has returned the warning message “longer object length is not a multiple of shorter object length”.

The reason for this is that we have tried to add two vector objects with different length (i.e. a vector containing five elements and a vector containing six elements).

The R programming language therefore had to cycle through the vector with shorter length and use the first element twice, i.e. the last element 6 of the second vector was added to the first element 1 of the first vector.

So how can we solve this problem?

 

Example 2: Fix the Warning Message – longer object length is not a multiple of shorter object length

In this example, I’ll illustrate how to avoid the warning message “longer object length is not a multiple of shorter object length”. For this, we simply have to use two data objects with the same length:

1:5 + 1:5                     # Using two vectors with same length
# [1]  2  4  6  8 10

Looks good!

 

Video, Further Resources & Summary

Would you like to know more about warnings in R? Then you may have a look at the following video of my YouTube channel. I illustrate the R programming codes of this tutorial in the video.

 

The YouTube video will be added soon.

 

In addition, I can recommend having a look at the related tutorials on my website:

 

Summary: At this point you should have learned how to handle the warning message “longer object length is not a multiple of shorter object length” in R programming. In case you have any further questions and/or comments, let me know in the comments.

 

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.

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

Menu
Top