开始使用免费开始使用

对长格式数据排序

我们已经把选择数据转换为长格式,存放在 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)
编辑并运行代码