5.1. Exercises

Melting Questions

Applying Melt

Instructions:
Running a coding exercise for the first time could take a bit of time for everything to load. Be patient, it could take a few minutes.

When you see ____ in a coding exercise, replace it with what you assume to be the correct code. Run it and see if you obtain the desired output. Submit your code to validate if you were correct.

Let’s take a look at some new untidy data that we have named lego.

Let’s melt this so that the 2 new columns named matte and transparent become a single one. These columns refer to the opacity of the blocks and the values refer to the number of pieces of each included in the set. Since our variable of interest in this scenario is opacity, we need to combine the two measurements into one column.

Tasks:

  • melt the dataframe columns matte and transparent into a single column named opacity and name the values column quantity.
  • Name the new dataframe tidied_lego.
Hint 1
  • Are you melting the correct columns named matte and transparent?
  • Are you making sure to use all the columns (except matte and transparent) in the argument id_vars?
  • Have you set all arguments (id_vars, value_vars, var_name, and value_name)?
Fully worked solution: