Output
[1] 6 8 10 12 14
Here we have created two vectors which are firstVector and secondVector. After creating both vectors we have created third vector VectorAfterAddition which is the addition of two vectors created earlier. We can see the result as in the below image, and clearly both vector elements have been added.
Now we shall see different cases while adding vectors in R.
Case 1 - Adding Vectors of Different Length
When we try to add vectors of different lengths the R studio gives a warning message as the longer object length is not a multiple of the shorter object length.
Let's see how it works.
First, we shall create two vectors, and after that, we shall create another vector with the addition of these two vectors.