R Programming: Create a List Containing 15 Capital Letters Starting from 'E'
Write a R program to create a list named s containing sequence of 15 capital letters, starting from ‘E’.
Sample Solution :
R Programming Code :
# Create a list named 'l' containing a sequence of 15 capital letters, starting from 'E'
l = LETTERS[match("E", LETTERS):(match("E", LETTERS)+15)]
# Print the message indicating the content of the list
print("Content of the list:")
# Print a description of the sequence of letters in the list
print("Sequence of 15 capital letters, starting from ‘E’-")
# Print the list 'l'
print(l)
Output:
[1] "Content of the list:" [1] "Sequence of 15 capital letters, starting from ‘E’-" [1] "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T
Explanation:
- Create a List l:
- LETTERS is a built-in R vector containing all uppercase letters from A to Z.
- match("E", LETTERS) finds the position of "E" in the LETTERS vector, which is 5.
- LETTERS[match("E", LETTERS):(match("E", LETTERS)+15)] selects a subset of LETTERS starting from "E" and includes the next 15 letters.
- The result is a vector of 15 letters starting from "E" through "T".
- Print Message:
- print("Content of the list:") outputs the text "Content of the list:" to indicate what will be displayed next.
- Print Description:
- print("Sequence of 15 capital letters, starting from ‘E’-") provides a description of the content of the list.
- Print List:
- print(l) displays the list l which contains the sequence of 15 capital letters starting from "E".
R Programming Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a R program to assign NULL to a given list element.
Next: Write a R program to add 10 to each element of the first vector in a given list.
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