Reputation: 5456
I would like to create ASCII characters in loop based on an integer variable. The result should be like this, but without the character vector:
v<-c("A","B","C","D","E")
for (i in 1:5) print(paste("ASCII:",v[i]))
If I start with
for (i in 65:69)
how do I continue?
Thanks&kind regards
Upvotes: 2
Views: 1724
Reputation: 35324
Use intToUtf8()
:
for (i in 65:69) print(paste('ASCII:',intToUtf8(i)));
## [1] "ASCII: A"
## [1] "ASCII: B"
## [1] "ASCII: C"
## [1] "ASCII: D"
## [1] "ASCII: E"
This is not directly relevant to your question, but we can utilize the multiple
argument of intToUtf8()
to generate a character vector of the output in one line:
paste('ASCII:',intToUtf8(65:69,T));
## [1] "ASCII: A" "ASCII: B" "ASCII: C" "ASCII: D" "ASCII: E"
Upvotes: 4