reshape2

reshape2 is a package that consists mainly of two functions: melt and dcast/acast. Generally, it could be said that melt() transforms one row to multiple and shorter rows while dcast() and acast() do exactly the opposite.

The melt() function, basically, transforms one row of data to many by pivoting a set of variables (the measure variables) over a set of other variables (the id variables). The function is called as follows:

melt(dataset,id.vars,measure.vars,variable_name)

The id variables are usually factors or characters while the measure variables are the numeric ones. In fact, this is the behavior by default if none of the arguments are specified. variable_name is the name that adopts the column where the variables are specified (

Get Learning Shiny now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.