大家選了什麼?
在建立模型之前,我們想先了解,人在不同產品屬性下會怎麼選。最好的做法是計算具有特定特徵的車被選中的次數。在這個練習中,我們聚焦在變速箱這個特徵,並用 xtabs() 函式來統計手排與自排被選中的次數。
本練習屬於課程
R 的行銷選擇模型
練習說明
- 將
xtabs()函式中的公式改成choice ~ trans,也就是「對trans變數的每個層級,加總choice變數」。 - 在主控台輸入名稱,列印
chosen_by_trans表格。手排與自排的車分別被選了幾次? - 使用
barplot()函式繪製chosen_by_trans物件。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create a table of chosen sportscars by transmission type
chosen_by_trans <- xtabs(___, data = sportscar)
# Print the chosen_by_trans table to the console
# Plot the chosen_by_trans object
barplot(___)