我有:
x<- c("20% cotton 30% textile 50% other", "75.5% plastic 24.5% other")我如何才能将它更改为
c("20% cotton, 30% textile, 50% other", "75.5% plastic, 24.5% other")gsub("[:alpha:] ",y)不起作用,因为"eat“是单词中的最后一个符号。
发布于 2019-09-09 04:06:42
基于该模式的选项是匹配一个或多个空格(+),后跟作为组((...))捕获的数字(\\d),并在replacement中插入,,后跟空格和所捕获组的反向引用(\\1
gsub(" +(\\d)", ", \\1", x)
#[1] "20% cotton, 30% textile, 50% other" "75.5% plastic, 24.5% other" https://stackoverflow.com/questions/57845370
复制相似问题