R Programming: Compute sum, mean and product of a given vector elements
R Programming: Basic Exercise-23 with Solution
Write a R program to compute sum, mean and product of a given vector elements.
Sample Solution :
R Programming Code :
nums = c(10, 20, 30) print('Original vector:') print(nums) print(paste("Sum of vector elements:",sum(nums))) print(paste("Mean of vector elements:",mean(nums))) print(paste("Product of vector elements:",prod(nums)))
 "Original vector:"  10 20 30  "Sum of vector elements: 60"  "Mean of vector elements: 20"  "Product of vector elements: 6000"
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 bell curve of a random normal distribution.
Next: Write a R program to create a list of heterogeneous data, which include character, numeric and logical vectors. Print the lists.
Test your Python skills with w3resource's quiz
What is the difficulty level of this exercise?
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework