
1.2
unnest_tokens
関数
■
3
1.2
unnest_tokens
関数
エミリー・ディキンソンは、
55
年の生涯においてすばらしい文学作品を残してい
ます。次は彼女の有名な詩の一節です
*
1
。
text <- c("Because I could not stop for Death -",
"He kindly stopped for me -",
"The Carriage held but just Ourselves -",
"and Immortality")
text
## [1] "Because I could not stop for Death -" "He kindly stopped for me -"
## [3] "The Carriage held but just Ourselves -" "and
Immortality"
これは分析したいと思う文字ベクトルの典型例です。これを整理テキストのデー
タセットに変換するためには、まずこれをデータフレームに変換する必要があり
ます。
library(dplyr)
text_df <- data_frame(line = 1:4, text = text)
text_df
## # A tibble: 4
×
2
## line text
## <int> <chr>
## 1 1 Because I could not stop for Death -
## 2 2 He kindly stopped for me - ...