どうも、ちょげ(@chogetarou)です。
文字列(string)を特定の区切り文字で分割したベクトル(vector)に変換する方法を紹介します。
方法

文字列(string)を特定の区切り文字で分割したベクトル(vector)に変換するには、unlist()とstrsplit()を使います。
まず、unlist()を呼び出し、unlist()の引数でstrsplit()を呼び出します。
そして、strsplit()の第1引数に文字列、第2引数に区切り文字を指定します。
#text=対象の文字列, sep=区切り文字
result <- unlist(strsplit(text, sep))
上記のunlist()は、対象の文字列(string)を区切り文字で分割したベクトル(vector)を返します。
使用例
text <- "AB,CDE,FG,HIJ,K"
result <- unlist(strsplit(text, ","))
print(result)
出力:
> print(result)
[1] "AB" "CDE" "FG" "HIJ" "K"
コメント