排序長格式資料
好,現在我們已經把選擇資料轉成長格式放在 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)