次のような文字列の文字ベクトルがあります。
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+","_")
しかし、これを1つのコマンドで実行できますか?次のような出力を取得できます:
x
[1]"weather_is_good_today"
[2]"it_will_rain_tomorrow"
[3]"do_not_get_angry"
助けてくれてありがとう。