Sequence of Alphabetical Character Letters from A-Z in R - GeeksforGeeks

23 Sep, 2021
In this article, we are going to discuss how to get a sequence of character letters from A-Z in R programming language.
We will get all letters in lowercase sequence by using the letters function
Syntax:
letters
Example: Return all lowercase letters using letters function
R
# return all lower case letters in sequenceprint(letters)
Output:
 [1] “a” “b” “c” “d” “e” “f” “g” “h” “i” “j” “k” “l” “m” “n” “o” “p” “q” “r” “s”
[20] “t” “u” “v” “w” “x” “y” “z”
We will get all letters in uppercase sequence by using LETTERS function.
Syntax:
LETTERS
Example: Return all uppercase letters using LETTERS  function
R
# return all upper case letters in sequenceprint(LETTERS)
Output:
[1] “A” “B” “C” “D” “E” “F” “G” “H” “I” “J” “K” “L” “M” “N” “O” “P” “Q” “R” “S”
[20] “T” “U” “V” “W” “X” “Y” “Z”
We can get the subsequence of letters using the index. Index starts with 1 and ends with 26 (since there are 26 letters from a to z). We are getting from letters/LETTERS function.
Syntax:
letters[start:end]
LETTERS[start:end]
Where, start is the starting letter index and end is the ending letter index.
Example: R program to get subsequence letters using index
R
# return all upper case letters from # index 1 to index 12print(LETTERS[1:12])  # return all lower case letters from# index 1 to index 12print(letters[1:12])  # return all upper case letters from# index 5 to index 26print(LETTERS[5:26])  # return all lower case letters from# index 5 to index 26print(letters[5:26])
Output:
[1] “A” “B” “C” “D” “E” “F” “G” “H” “I” “J” “K” “L”
[1] “a” “b” “c” “d” “e” “f” “g” “h” “i” “j” “k” “l”
[1] “E” “F” “G” “H” “I” “J” “K” “L” “M” “N” “O” “P” “Q” “R” “S” “T” “U” “V” “W” “X” “Y” “Z”
[1] “e” “f” “g” “h” “i” “j” “k” “l” “m” “n” “o” “p” “q” “r” “s” “t” “u” “v” “w” “x” “y” “z”
Here in this scenario, we will get the random letters randomly using sample() function. sample() function is used to generate random letters
Syntax:
sample(letters/LETTERS,size)
Where,
letters/LETTERS  is a function that is a first parameter to display letters in lower/upper case
size is used to get the number of letters randomly
Example: R program to display random letters
R
# display 20 random lower case letterssample(letters, 20)  # display 20 random upper case letterssample(LETTERS, 20)  # display 17 random lower case letterssample(letters, 17)  # display 17 random upper case letterssample(LETTERS, 17)
Output:
[1] “k” “p” “g” “c” “j” “r” “s” “u” “h” “i” “d” “o” “a” “m” “y” “f” “t” “l” “q” “b”
[1] “D” “A” “K” “G” “W” “E” “N” “C” “P” “T” “M” “S” “F” “V” “B” “R” “H” “Y” “X” “I”
[1] “i” “v” “f” “u” “s” “d” “x” “w” “h” “a” “p” “b” “y” “o” “c” “z” “l”
[1] “Y” “X” “Z” “C” “N” “M” “A” “Q” “V” “R” “O” “E” “B” “J” “F” “U” “I”
Picked
R String-Programs
R-strings
R Language
R Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Change Color of Bars in Barchart using ggplot2 in R
Group by function in R using Dplyr
How to Change Axis Scales in R Plots?
How to Split Column Into Multiple Columns in R DataFrame?
Replace Specific Characters in String in R
How to Split Column Into Multiple Columns in R DataFrame?
Replace Specific Characters in String in R
How to filter R DataFrame by values in a column?
How to filter R dataframe by multiple conditions?
Convert Matrix to Dataframe in R