Sequence of Alphabetical Character Letters from A-Z in R
Last Updated :
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.
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"
Similar Reads
Remove All Special Characters from String in R In this article, we are going to remove all special characters from strings in R Programming language. For this, we will use the str_replace_all() method to remove non-alphanumeric and punctuations which is available in stringr package. Installation To install this library type the below command in
1 min read
How to Sort Values Alphabetically in R? In this article, we will discuss how to sort values alphabetically in R Programming Language. Sorting vector Alphabetically Here we are using sort() function to sort a vector alphabetically. Syntax: sort(vector) where, vector is the input vector Example: R # create a vector vector1 = c('G', 'E', 'E'
2 min read
Count Number of Characters in String in R In this article, we are going to see how to get the number of characters in a string in R Programming Language. The number of characters in a string refers to the length of the string.Examples:Input: GeeksforgeeksOutput: 13Explanation: Total 13 characters in the given string.Input: Hello worldOutput
2 min read
Extract Numbers from Character String Vector in R In this article, we are going to see how to extract Numbers from Character String Vector in R Programming Language. There are different approaches to extract numbers from character string vectors using some in-built functions. It can be done in the following ways:Using the gsub() functionUsing the g
2 min read
How to Check if Characters are Present in a String in R. In this article, we will learn how to check the presence of a character, substring or number in a string using R Programming Language. This can be useful for tasks where we want to filter data, pattern matching or data cleaning. We generally use grepl() function, a versatile tool that is used for ch
6 min read