精确重复数的量词grepl

时间:2018-12-13 12:26:46

标签: r if-statement grepl

我试图在字符串tst中分别将“ S00”,“ S0”或“ S”添加为1或2或3倍长。 结果就是S004,S008,S009,S022,S051,...,S753。

尝试使用ifelsegrepl,但未成功:

tst <- as.character(c(4,8,9,22,51,56,57,12,15,150,147,852,654,753))
ifelse(grepl("[0-9]{1} ", tst), paste("S00", tst,sep = ""), 
    ifelse(grepl("[0-9]{2} ", tst), paste("S0", tst,sep = ""), "S"))

0 个答案:

没有答案