Alberto Giudici compares tidyr to reshape2 for data cleansing in R:
We see a different behaviour:
gather()
has broughtmessy
into a long data format with a warning by treating all columns as variable, whilemelt()
has treated trt as an “id variables”. Id columns are the columns that contain the identifier of the observation that is represented as a row in our data set. Indeed, ifmelt()
does not receive any id.variables specification, then it will use the factor or character columns as id variables.gather()
requires the columns that needs to be treated as ids, all the other columns are going to be used as key-value pairs.Despite those last different results, we have seen that the two functions can be used to perform the exactly same operations on data frames, and only on data frames! Indeed,
gather()
cannot handle matrices or arrays, whilemelt()
can as shown below.
It seems that these two tools have some overlap, but each has its own point of focus: tidyr is simpler for data tidying, whereas reshape2 has functionality (like data aggregation) which tidyr does not include.