R Programming: Add 10 to each element of the first vector in a given list
R Programming: List Exercise-16 with Solution
Write a R program to Add 10 to each element of the first vector in a given list.
Sample list: (g1 = 1:10, g2 = "R Programming", g3 = "HTML")
Sample Solution :
R Programming Code :
list1 = list(g1 = 1:10, g2 = "R Programming", g3 = "HTML")
print("Original list:")
print(list1)
print("New list:")
list1$g1 = list1$g1 + 10
print(list1$g1)
Sample Output:
[1] "Original list:" $g1 [1] 1 2 3 4 5 6 7 8 9 10 $g2 [1] "R Programming" $g3 [1] "HTML" [1] "New list:" [1] 11 12 13 14 15 16 17 18 19 20
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 list named s containing sequence of 15 capital letters, starting from ‘E’.
Next: Write a R program to extract all elements except the third element of the first vector of a given list.
Test your Programming skills with w3resource's quiz.
What is the difficulty level of this exercise?
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- 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
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework