As mentioned before, reshape2
was a complete rewrite of the reshape
package, based on around 5 years of experience in using and developing the latter. This update also included some trade-offs, as the original reshape tasks were split among multiple packages. Thus, reshape2
now offers a lot less compared to the kind of magic features that were supported by reshape
. Just check, for example reshape::cast
; especially the margins
and add.missing
argument!
But as it turns out, even reshape2
offers a lot more than simply melting and casting data frames. The birth of the tidyr
package was inspired by this fact: to have a package in the Hadleyverse that supports easy data cleaning and transformation between the long and wide table formats. In tidyr
parlance, these operations are called gather
and spread
.
Just to give a quick example of this new syntax, let's re-implement the previous examples:
> library(tidyr) > str(gather(hflights[, c('Month', 'ActualElapsedTime', 'AirTime')], + variable, value, -Month)) 'data.frame': 454992 obs. of 3 variables: $ Month : int 1 1 1 1 1 1 1 1 1 1 ... $ variable: Factor w/ 2 levels "ActualElapsedTime",..: 1 1 1 1 ... $ value : int 60 60 70 70 62 64 70 59 71 70 ...
18.188.211.106