A Spanish journalist friend told me his following problem: he had a dataset of longitudinal data (say, 10 years, one data point per year) for several countries. While gathering the data, he chose a wide structure: a column for the country name and a column for each year of data. Something like this:

    country        1990       1991       1992       1993        1994       1995       1996        1997        1998        1999
1  country0 -0.19232092 -1.3835283 -0.1250833  0.3550214  0.02175168  1.0681174 -0.1245599  0.59793832 -0.04972589  1.68351806
2  country1  1.18265157  0.2129221 -0.8748639 -0.8477623  0.96472823 -0.4031558  0.3941119  1.96712668  0.87177788  0.57995232
3  country2  0.38952943  0.1390607  1.5761959 -0.7746558  1.43864927 -1.5993779 -1.0625679  1.82467112  0.46716863 -1.32256861
4  country3 -0.39058429  1.6097480 -1.7121666 -1.0776926  1.77838632 -0.0418115  0.4624286  0.86472406  0.74149136 -0.52444027
5  country4 -0.04303374  0.7729283  0.5251493 -0.5483232  1.49131869  0.3530868  0.7276152 -0.71285442 -1.10711731  0.85837911
6  country5 -1.73290239  0.3180153  0.8468061  0.2105316  0.51485224 -0.9331017  1.2984709 -2.94175512 -0.40254126 -1.06511146
7  country6  0.67369475 -0.4168123 -0.6155582 -0.5394701  1.19880097  0.2559996 -0.7793989  0.03637134  0.42253039 -0.98159929
8  country7 -1.32559918  0.1982958 -0.6558728  0.7013966 -0.93422206 -0.1759437 -0.8640791 -2.26324850 -3.07157167 -0.02595718
9  country8  1.12161820  0.2764757  0.9093099 -0.8094704 -0.73386643  0.5272047  0.4205902  1.85222293 -0.14390907 -1.36531657
10 country9  2.30570741  0.4384453 -0.1084297  0.7452369  1.89283497  0.7171059 -0.9567151 -0.75744265  0.80635835 -1.53992670

This makes a lot of sense for some things, but not for others. In this case, my friend wanted to visualize the data by creating a map using CartoDB, and they needed the data in long format: one column for the country, one column for the year, and one column for whatever value is to be plotted. It took him half an our to reshape his data by hand. Here is how it is done in R:

library(reshape2)
mydata_long <- melt(mydata, id.vars = "country", variable.name = "year")

And that's it:

> head(mydata_long)
   country year       value
1 country0 1990 -0.19232092
2 country1 1990  1.18265157
3 country2 1990  0.38952943
4 country3 1990 -0.39058429
5 country4 1990 -0.04303374
6 country5 1990 -1.73290239