開始使用免費開始

排序長格式資料

很好,我們已經把選擇資料整理成 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)
編輯並執行程式碼