开始使用免费开始使用

从宽表转换为长表

已为您加载 chocolate_wide 数据。请使用 reshape() 将其转换为长表格式。我已为您准备了让新数据列名正确所需的输入。接下来,请您补充最重要的参数,告诉 reshape() 应如何转换数据。

本练习是课程的一部分

R 中的营销选择建模

查看课程

练习说明

  • 填写要开始处理的数据:chocolate_wide。
  • 填写要转换成的形式:long。
  • 填写每道选择题中 3 个可选项的 Brand、Price 和 Type 所在列。您可能需要用 str() 或 head() 查看数据来确认。我已为您先填写了 Brand 的列。
  • 完成 reshape() 命令后,使用 head() 确认数据已正确转换。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# use reshape() to change the data from wide to long 
chocolate <- reshape(data= ___ , direction="____", 
                     varying = list(Brand=3:5, Price=____, Type=____), 
                     v.names=c("Brand", "Price", "Type"), timevar="Alt")
                     
# use head() to confirm that the data has been properly transformed
编辑并运行代码