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