http://tidytextmining.com/sentiment.html#the-sentiments-datasetに基づいてセンチメント分析を実行しようとしています。感情分析を行う前に、自分のデータセットをきちんとしたフォーマットに変換する必要があります。ワードカウントでデータフレームをチブルに変換
私のデータセットの形式は次のとおりです。行につき1つの観察に変換するために
x <- c("test1" , "test2")
y <- c("this is test text1" , "this is test text2")
res <- data.frame("url" = x, "text" = y)
res
url text
1 test1 this is test text1
2 test2 this is test text2
は、テキスト列を処理し、それがそのURLの出現単語と回数を含む新しい列を追加する必要があります。同じURLが複数の行に表示されます。ここで
は私の試みです:
library(tidyverse)
x <- c("test1" , "test2")
y <- c("this is test text1" , "this is test text2")
res <- data.frame("url" = x, "text" = y)
res
res_1 <- data.frame(res$text)
res_2 <- as_tibble(res_1)
res_2 %>% count(res.text, sort = TRUE)
返す:
# A tibble: 2 x 2
res.text n
<fctr> <int>
1 this is test text1 1
2 this is test text2 1
をRES $テキストデータフレーム内の単語をカウントし、感情分析を実行するためにURLを維持するためにどのように?
更新:
x <- c("test1" , "test2")
y <- c("this is test text1" , "this is test text2")
res <- data.frame("url" = x, "text" = y)
res
res %>%
group_by(url) %>%
transform(text = strsplit(text, " ", fixed = TRUE)) %>%
unnest() %>%
count(url, text)
を返すエラー:あなたがhttp://tidytextmining.com/sentiment.html#the-sentiments-dataset
なぜ変換する必要がありますか?言い換えれば、あなたのタイトルは実際の質問を表現していないようです。あなたは言葉がURLごとにできることを望んでいるようです。私は考えられる可能性のある1つのチベットのアプローチは、 'res%>%group_by(url)%>%transform(text = strsplit(text、" fixed、TRUE))%>%unnest()%>%count(url、text ) '(' text'は文字列で要素ではないと仮定します) –
@DavidArenburg更新をご覧ください –