開始使用免費開始

排序長格式資料

好,現在我們已經把選擇資料轉成長格式放在 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)
編輯並執行程式碼