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.
私は文字列を持っています:
string1 <- "This is my string"
次のようなベクトルに変換したいと思います。
vector1 "This" "is" "my" "string"
どうすればよいですか?tmパッケージを使用してマトリックスに変換してからマトリックスに変換できることはわかっていますtermDocumentMatrixが、単語がアルファベット順になり、同じ順序を維持する必要があります。
tm
termDocumentMatrix
このタスクを実行するには、strsplit を使用できます。
string1 <- "This is my string" strsplit(string1, " ")[[1]] #[1] "This" "is" "my" "string"
Dason とは少し異なりますが、これは改行を含む任意の量の空白で分割されます。
string1 <- "This is my string" strsplit(string1, "\\s+")[[1]]