始める無料で始める

グループ化集計の練習

pivot_wider() は、グループ化集計の結果に対しても組み合わせて使うことができます。

この演習はコースの一部です

Rで始めるテキスト分析

コースを見る

演習の手順

  • tidy_twitter を afinn 感情辞書に結合します。
  • クレームの有無を示すラベルと、ユーザーが認証済みかどうかの両方でグループ化します。
  • データを要約して、新しい列 aggregate_value を作成し、value の合計を入れます。
  • complaint_label 列と aggregate_value 列をワイドに展開します。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

tidy_twitter %>% 
  # Append the afinn sentiment dictionary
  ___(___) %>% 
  # Group by both complaint label and whether or not the user is verified
  ___(___) %>% 
  # Summarize the data with an aggregate_value = sum(value)
  ___(___) %>% 
  # Spread the complaint_label and aggregate_value columns
  ___(___) %>% 
  mutate(overall_sentiment = Complaint + `Non-Complaint`)
コードを編集して実行