使用 R 创建字母的顺序列表
我希望能够在 R 中创建字母序列(以协助从 SPSS 文件导入数据)
创建数字序列非常容易,例如:
seq(1,1000)
[1] 1 2 3 4 5 6 ... 1000
paste("something_",1:12,sep="")
[1] something1 something2 ... something12
但是是否有附加、粘贴或创建的功能像这样的字母序列?
paste("This_",a:z,sep="")
[1]This_a This_b This_c ... This_4z
I would like to be able to create a sequence of letters in R (to assist in importing data from a SPSS file)
It's quite easy to create a sequence of numbers, for example:
seq(1,1000)
[1] 1 2 3 4 5 6 ... 1000
paste("something_",1:12,sep="")
[1] something1 something2 ... something12
But is there any functionality for appending, pasting, or creating sequences of letters like this?
paste("This_",a:z,sep="")
[1]This_a This_b This_c ... This_4z
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这就是您正在寻找的:
This is what you're looking for:
你看了一下
,这不是你想要的吗?另外还有
paste()
和相关函数。编辑:也许要粘贴的
collapse=
正是您所需要的:Did you look at
and doesn't that do what you want? Else there are
paste()
and related functions.Edit: Maybe the
collapse=
to paste is what you need:对于“a”到“z”,
对于“A”到“Z”,
它要打印序列中的特定字母,比如说,如果您只想要 j、k 和 j、k 等。我
for "a" to "z" it's
for "A" to "Z" its
And to print specific letters in the sequence, say if you want only j, k & l
我猜你想得到 A-1、A-2、A-3、B-1、B-2、B-3、C-1、C-2、C-3 等等...
我尝试过
但是这样我就得到了
A-1, B-2, C-3, D-1, E-2, F-3, G-1, H-2, I-3, J-1" "A-1, B -2、C-3、D-1、E-2、F-3、G-1、H-2、I-3、J-1、A-1、B-2、C-3、D-1 ,E-2,F-3,G-1,H-2,I-3,J-1”
我也尝试过
但得到了相同的结果..
我怎样才能获得所需的序列
Guess you want to get A-1, A-2, A-3, B-1, B-2, B-3, C-1, C-2, C-3 and so on...
I tried this
But this way I get
A-1, B-2, C-3, D-1, E-2, F-3, G-1, H-2, I-3, J-1" "A-1, B-2, C-3, D-1, E-2, F-3, G-1, H-2, I-3, J-1, A-1, B-2, C-3, D-1, E-2, F-3, G-1, H-2, I-3, J-1"
I also tried
but got the same results..
How can I get the desired sequence