Good afternoon,
I'm trying to create a cartesian product in R with the letters of the alphabet.
What I'm actually trying is this:
First I create a matrix with the letters
a <- as.matrix(seq(97,122,by=1))
Then I create a data frame with 2 columns with all the combinations
b <- expand.grid(a, a)
Finally I combine the 2 columns
apply(b,1,paste,collapse=" ")
The problem I have is that I can't find a way to transform those "decimals" to its Ascii character.
I have tried several things like rawToChar and gsub unsuccessfully.
Can somebody point me in the right direction?
Thanks
To get the letter, character, sign or symbol "R" : ( Capital letter R ) on computers with Windows operating system: 1) Press the "Alt" key on your keyboard, and do not let go. 2) While keep press "Alt", on your keyboard type the number "82", which is the number of the letter or symbol "R" in ASCII table.
In short \r has ASCII value 13 (CR) and \n has ASCII value 10 (LF).
charToRaw converts a length-one character string to raw bytes. It does so without taking into account any declared encoding (see Encoding ). rawToChar converts raw bytes either to a single character string or a character vector of single bytes. (Note that a single character string could contain embedded nuls.)
A very easy way to return a character based on its ASCII code is the function intToUtf8
. It also works for vectors including multiple integers and returns the corresponding characters as one string.
vec <- 97:122
intToUtf8(vec)
# [1] "abcdefghijklmnopqrstuvwxyz"
intToUtf8(65)
# [1] "A"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With