我有这样的字符串字符向量:
x <- c("weather is good_today","it. will rain tomorrow","do not* get_angry")
我想替换所有特殊字符和空格并用“_”替换它们。我用过这样str_replace all
的:stringr package
x1 <- str_replace_all(x,"[[:punct:]]","_")
x2 <- str_replace_all(x1,"\\s+","_")
但这可以在一个命令中完成,我可以得到这样的输出:
x
[1]"weather_is_good_today"
[2]"it_will_rain_tomorrow"
[3]"do_not_get_angry"
谢谢你的帮助。