"-"
开头并以"*"
结尾的值? "-"
开头但以"*"
结尾的值?例如,我的数据如下所示:
0.5, -0.4*, 1.8*, 2.5**, 0.8
谢谢!
答案 0 :(得分:0)
我们可以使用str_match()
或gsub()
(语法略有不同)。
library(stringr)
data = c("0.5", "-0.4*","1.8*", "2.5**", "0.8","-0.5")
#1. Matched all starting with - and ending without a star
str_match(data,"^-[0-9\\.]+[^\\*]$")
#2. Meches all not starting with - but ending with a star
str_match(data,"^[^-][0-9\\.]+\\*$")