从“A”-“Z”生成字符序列

发布于 2024-10-06 04:25:38 字数 183 浏览 0 评论 0原文

我可以像这样创建一个数字序列:

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

How do I make a string of characters from AZ?这不起作用:

seq(from=1, to=10)

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 work:

seq(from=1, to=10)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

不交电费瞎发啥光 2024-10-13 04:25:39

使用 LETTERSletters(分别表示大写和小写)。

Use LETTERS and letters (for uppercase and lowercase respectively).

简单 2024-10-13 04:25:39

使用带有 letters 和/或 LETTERS 的代码:

> LETTERS[seq( from = 1, to = 10 )]
 [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J"
> letters[seq( from = 1, to = 10 )]
 [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j"

Use the code you have with letters and/or LETTERS:

> LETTERS[seq( from = 1, to = 10 )]
 [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J"
> letters[seq( from = 1, to = 10 )]
 [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j"
蒗幽 2024-10-13 04:25:39

只需使用预定义变量 lettersLETTERS 即可。

为了完整起见,这里使用 seq

R> rawToChar(as.raw(seq(as.numeric(charToRaw('a')), as.numeric(charToRaw('z')))))
[1] "abcdefghijklmnopqrstuvwxyz"
R> 

Just use the predefined variables letters and LETTERS.

And for completeness, here it something using seq:

R> rawToChar(as.raw(seq(as.numeric(charToRaw('a')), as.numeric(charToRaw('z')))))
[1] "abcdefghijklmnopqrstuvwxyz"
R> 
土豪 2024-10-13 04:25:39

R.oo 包有一个 intToChar 函数,如果 LETTERSletters 不是任何值,则该函数使用 ASCII 值好的。 A 在 ASCII 中是 65:

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

或者您可以使用这样的事实:最低的 unicode 数字是 ascii,因此在 R 基中是 intToUtf8,如下所示:

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

或者使用 rawToChar

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

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"
爱你不解释 2024-10-13 04:25:39

LETTERS 返回 AZ

生成 AE 例如

大写:

> LETTERS[1:5]

小写

letters[1:5]

LETTERS returns A-Z

To generate A-E for instance

Uppercase:

> LETTERS[1:5]

Lowercase

letters[1:5]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文