変数の二値化
質問名を整理できたので、次は応答変数に取り組みます。元の分析では、ある行為を「やや失礼」または「とても失礼」と考える人の割合を見ていました。これを再現するには、現在の回答が入っている rude 変数を、「やや失礼」と「とても失礼」をまとめた形に変換する必要があります。
この演習はコースの一部です
tidyverse で学ぶカテゴリ型データ
演習の手順
- value 列が NA の行を削除します。
- 新しい変数 rude を作成します。value 列が "No, not rude at all" または "No, not at all rude" のときは 0、それ以外は 1 にします。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
dichotimized_data <- 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
___ %>%
# Dichotomize the value variable to make a new variable, rude
mutate(rude = if_else(value ___ c('No, not rude at all', 'No, not at all rude'), ___, ___))