排序長格式資料
很好,我們已經把選擇資料整理成 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)