. Advertisement .
..3..
. Advertisement .
..4..
Recently, I ran some of my r code, and it gave the warning text:
Longer object length is not a multiple of shorter object length
While searching, I realized that some people added some command lines in my sample above. But I don’t think it is the best way to correct the problem – longer object length is not a multiple of shorter object length. How would you explain this trouble? or Is there a better way? Below is the detail of the command that I used
#define two vectors: vector_a, vector_b
vector_a <- c(11, 22, 33, 44, 45)
vector_b <- c(60, 71, 80, 91)
#add the two vectors
vector_a + vector_b
The cause: The length of two vectors needs to be the same when plus them. In this case, vector vector_b is less than vector vector_a, thus, it occur the warning message.
Solution: Add 0 to the end of vector that has less than other, so it means to add 0 to the end of vector vector_b. From above, here is the suggestion: