MulaiMulai sekarang secara gratis

Convert from wide to long

The chocolate_wide data is loaded for you. I'd like you to convert it to long format using reshape(). I've gotten you started by providing the inputs required to get the columns in the new data labeled correctly. You can fill in the most important inputs that tell reshape() how to transform the data.

Latihan ini adalah bagian dari kursus

Choice Modeling for Marketing in R

Lihat Kursus

Petunjuk latihan

  • Fill in the data that we want to start with: chocolate_wide.
  • Fill in the form we want to tranform the data to: long.
  • Fill in the columns that contain the Brand, Price and Type for the three alternatives in each choice question. You may need to look at the data to figure this out using str() or head(). I've started by filling in the Brand columns for you.
  • After you've finished the reshape() command, use head() to confirm that the data has been properly transformed.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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
Edit dan Jalankan Kode