Sequence of Alphabetical Character Letters from A-Z in R

In this article, we are going to discuss how to get a sequence of character letters from A-Z in R programming language.

Return all lower case letters using letters function

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 sequence
print(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”

Return all upper case letters using LETTERS function

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 sequence
print(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”

Subsequence letters using range operation

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 12
print(LETTERS[1:12])
  
# return all lower case letters from
# index 1 to index 12
print(letters[1:12])
  
# return all upper case letters from
# index 5 to index 26
print(LETTERS[5:26])
  
# return all lower case letters from
# index 5 to index 26
print(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”

Random sequence of letters using sample() function

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 letters
sample(letters, 20)
  
# display 20 random upper case letters
sample(LETTERS, 20)
  
# display 17 random lower case letters
sample(letters, 17)
  
# display 17 random upper case letters
sample(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”



Contact Us