Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Rの文字ベクトルのすべての要素でダッシュをドットに置き換える簡単な方法はありますか?
input c("T-A-B", "C-L1") output c("T.A.B", "C.L1")
パッケージでヘルプを探していましstringiたが、答えが見つかりませんでした。機能はありstri_substituteますが、使い方がわかりません。
stringi
stri_substitute
このようなベースR(@docendo のおかげでベクトル化された gsub):
R
> gsub("-",".",c("T-A-B", "C-L1")) [1] "T.A.B" "C.L1"
またはstringr:
stringr
> library(stringr) > str_replace_all( c("T-A-B", "C-L1"),"-",".") [1] "T.A.B" "C.L1"