ロングデータを並べ替える
これで chocolate の選択データをロング形式に変換できましたが、整理するためにもう少し作業が必要です。まず、同じ選択質問の選択肢がまとまって表示されるように chocolate を並べ替えましょう。
この演習はコースの一部です
Rで学ぶマーケティングのための選択モデリング
演習の手順
order()関数に並べ替えの基準となる変数を入力します。順番はchocolate$Subject、chocolate$Trial、chocolate$Altです。new_orderを使ってchocolateデータフレームの行を並べ替えます。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Create the new order for the chocolate data frame
new_order <- order(____, ____, ____)
# Reorder the chocolate data frame to the new_order
chocolate <- chocolate[____,]
# Look at the head() of chocolate to see how it has been reordered
head(chocolate)