Modifier la variable Selection
La dernière étape pour convertir nos données au format long consiste à modifier la colonne Selection où le choix est stocké. Dans les données au format large, le choix est stocké sous forme d’entier indiquant quelle alternative a été choisie. Au format long, il doit s’agir d’une variable logique ou 0-1 indiquant l’alternative choisie.
Cet exercice fait partie du cours
Modélisation des choix pour le marketing en R
Instructions
- Utilisez
head()pour examiner la variableSelectionqui contient le choix. Remarquez queSelectioncontient un entier correspondant au numéro de l’alternative choisie. - Affectez
chocolate$Alt == chocolate$Selectionàchocolate$Selection. - Utilisez
head()pour voir comment la variableSelectiona été transformée.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Use head(chocolate) and look at the Selection variable.
# Transform the Selection variable to a logical indicator
chocolate$Selection <-
# Use head(chocolate) to see how the Selection variable has changed. Now it is logical.