始める無料で始める

データの要約

現在のデータは、1人×1質問あたり1行という形式のままです。グラフ化するには、各行が「質問」になり、その質問への回答を要約した情報を持つ形式に変換したいところです。

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

tidyverse で学ぶカテゴリ型データ

コースを見る

演習の手順

  • データセットを、質問(response_var)と、新しい列 perc_rude(各質問における rude 列の平均)の2列に要約してください。
  • 結果を rude_behaviors として保存し、新しいデータセットを表示しましょう。

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

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

rude_behaviors <- gathered_data %>%
    mutate(response_var = str_replace(response_var, '.*rude to ', '')) %>%
    mutate(response_var = str_replace(response_var, 'on a plane', '')) %>%
	# Remove rows that are NA in the value column
	filter(!is.na(value)) %>%
    mutate(rude = if_else(value %in% c("No, not rude at all", "No, not at all rude"), 0, 1)) %>%
    # Group by response_var
    ___ %>%
    # Create perc_rude, the percent considering each behavior rude
    ___

rude_behaviors
コードを編集して実行