我有一个字符串的字符向量,就像这样:
x <- c("weather is good_today","it. will rain tomorrow","do not* get_angry")
我想要用 "_" 替换所有特殊字符和空格。
我使用了 stringr 包
中的 str_replace_all
,代码如下:
x1 <- str_replace_all(x,"[[:punct:]]","_")
x2 <- str_replace_all(x1,"\\s+","_")
但是我能用一个命令完成这个操作,并且可以像这样获取输出吗:
But can this be done in one single command and I can get the output like this :
x
[1]"weather_is_good_today"
[2]"it_will_rain_tomorrow"
[3]"do_not_get_angry"
感谢任何帮助。