R Programming: Add two vectors of integers type and length 3
R Programming: Vector Exercise-2 with Solution
Write a R program to add two vectors of integers type and length 3.
Sample Solution :
R Programming Code :
x = c(10, 20, 30)
y = c(20, 10, 40)
print("Original Vectors:")
print(x)
print(y)
print("After adding two Vectors:")
z = x + y
print(z)
Sample Output:
[1] "Original Vectors:" [1] 10 20 30 [1] 20 10 40 [1] "After adding two Vectors:" [1] 30 30 70
R Programming Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a R program to create a vector of a specified type and length. Create vector of numeric, complex, logical and character types of length 6.
Next: Write a R program to append value to a given empty vector.
Test your Programming skills with w3resource's quiz.
What is the difficulty level of this exercise?
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics