Generate a sequence of characters from 'A'-'Z'

后端 未结 4 505
隐瞒了意图╮
隐瞒了意图╮ 2020-12-15 15:41

I can make a sequence of numbers like this:

s = seq(from=1, to=10, by=1)

How do I make a sequence of characters from A-Z? This doesn\'t wor

4条回答
  •  再見小時候
    2020-12-15 16:26

    R.oo package has an intToChar function, that uses ASCII values, if LETTERS and letters aren't any good. A is 65 in ASCII:

    > require(R.oo)
    > intToChar(65:79)
     [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O"
    

    or you can use the fact that the lowest unicode numbers are ascii and hence intToUtf8 in R-base like this:

    > intToUtf8(65:78,multiple=TRUE)
     [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N"
    

    or faff around with rawToChar:

    > rawToChar(as.raw(65:78))
    [1] "ABCDEFGHIJKLMN"
    

提交回复
热议问题