Sequence of Alphabetical Character Letters from A-Z in R (3 Examples)


In this R tutorial you’ll learn how to generate a sequence of character letters.

The post will consist of this content:

Let’s dive right into the examples…


Example 1: Sequence of Lower & Upper Case Letters from A-Z

This example illustrates how to get a sequence of alphabetical character letters ranging from A-Z.

Fortunately, the R programming language provides two letter data objects by default.

The data object “letters” contains all alphabetical letters in lower case format

letters                           # Return lower case letters
#  [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z"

…and the data object “LETTERS” contains all alphabetical letters in upper case format:

LETTERS                           # Return upper case letters
#  [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z"

In the following examples, I’ll explain how to use these data objects to create other letter sequences in R.


Example 2: Create Subsequence of Letters

In Example 2, I’ll explain how to select a subsequence of alphabetical character letters in R.

Let’s assume that we want to extract an alphabetical range from the third to the eighth letter of the alphabet. Then, we can subset the letters object as shown below:

my_seq1 <- letters[3:8]           # Subsequence of alphabet
my_seq1                           # Print subsequence
# [1] "c" "d" "e" "f" "g" "h"


Example 3: Create Random Sequence of Letters

It is also possible to generate a random sequence of character letters by applying the sample function to the letters object as shown below:

set.seed(928374)                  # Set seed
my_seq2 <- sample(letters, 10)    # Sample random letters
my_seq2                           # Print random sequence
#  [1] "b" "m" "x" "i" "o" "e" "c" "v" "f" "h"

The previous output of the RStudio console shows a randomly drawn sequence of letters with a length of ten.


Video, Further Resources & Summary

Do you want to learn more about character letters in R? Then you could have a look at the following video of my YouTube channel. In the video instruction, I’m explaining the contents of this tutorial:



In addition, you may have a look at the related articles that I have published on my website.


This tutorial has shown how to get a sequence of alphabetical character letters in the R programming language. Let me know in the comments below, if you have additional questions. Furthermore, please subscribe to my email newsletter in order to get updates on the newest articles.


Subscribe to the Statistics Globe Newsletter

Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.