LETTERS represent the 26 upper-case character letters from A-Z of the alphabet. It is one of the built-in constants in R. This guide shows you how to create a sequence of letters in R using LETTERS.
Creating a sequence of all upper-case letters
You will get all 26 alphabets in upper-case using the LETTERS function. Make sure to type the syntax in upper-case.
Syntax
LETTERS
Example
LETTERS
print(LETTERS)
Output
> print(LETTERS)
[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"
Creating a subsequence of upper-case letters
We can return a subsequence of upper-case letters using an index. As there are 26 letters in the alphabet, the index begins with 1 and ends with 26.
Syntax
LETTERS[start:end]
Example
Let us say you want to print the upper-case alphabet from the fifth to the tenth letter of the alphabet.
print(LETTERS[5:10])
Output
> print(LETTERS[5:10])
[1] "E" "F" "G" "H" "I" "J"
Creating a random sequence of upper-case letters
You can create a random sequence of letters of a specific size using the sample() function.
Syntax
sample(LETTERS, size)
Here, LETTERS represents the upper-case letters, and size represents the number of random letters.
Example
print(sample(LETTERS,5))
Output
> print(sample(LETTERS,5))
[1] "F" "O" "R" "Q" "E"