简体   繁体   English

如何用R中的字符创建相同数字的数字序列

[英]how to create sequence of numbers in same digit with a character in R

I'd like to make a sequence of numbers with a character in R as below. 我想用R中的一个字符组成一个数字序列,如下所示。

[H01, H02, H03, ... , H24]

I can only generate numbering characters like 我只能生成编号字符,例如

[H1, H2, H3, ... , H24] 

with a command 用命令

paste0("H", 1:24)

any tips for this? 有什么提示吗?

sprintf is similar with printf of C, so you can control the format exactly as below: sprintfprintf相似,因此您可以完全按照以下方式控制格式:

sprintf("H%02d", 1:24)
[1] "H01" "H02" "H03" "H04" "H05" "H06" "H07" "H08" "H09" "H10" "H11" "H12" "H13" "H14" "H15" "H16" "H17" "H18" "H19" "H20" "H21"
[22] "H22" "H23" "H24"

Also see this . 另请参阅

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM