Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print a character list from A to Z?

Tags:

r

In R, how can I print a character list from A to Z? With integers I can say:

my_list = c(1:10)
> my_list
 [1]  1  2  3  4  5  6  7  8  9 10

But can I do the same with characters? e.g.

my_char_list = c(A:Z)
my_char_list = c("A":"Z")

These don't work, I want the output to be: "A" "B" "C" "D", or separated by commas.

like image 809
John Avatar asked Mar 16 '10 18:03

John


People also ask

How do I print a character in a string?

printf("%c\n", string[n-1]); since you do not want to go out bounds of your array (and cause Undefined Behavior), or print two characters next of the requested character, since when I ask for the 1st character, you should print string[0] , when I ask for the 2nd, you should print string[1] , and so on.


2 Answers

LETTERS

"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"
like image 131
George Dontas Avatar answered Oct 15 '22 20:10

George Dontas


> 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"
[25] "Y" "Z"
> 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"
[25] "y" "z"
> LETTERS[5:10]
[1] "E" "F" "G" "H" "I" "J"
> 
like image 39
William Doane Avatar answered Oct 15 '22 20:10

William Doane