r/R_Programming • • Jul 08 '16

Wide to long?

My head does not want to grasp the wide vs long variables.. I have a df containing:

"2010"	"2011"	"2012"	"2013"	"2014"	"2015"
5007	4626		4563		4593		4677		5069

How do I make it 6 observations of 2 variables instead of the below?

> str(x)
'data.frame':	1 obs. of  6 variables:
1 Upvotes

6 comments sorted by

View all comments

Show parent comment

1

u/repsaj23 Jul 24 '16

I'm not sure, but hasn't the reshape2 package been succeeded by the tidyr package?

3

u/vmarg Jul 28 '16

It has. Tidyr has two main functions: gather (which is very similar to melt of reshape2, and converts data frames from wide to long format), and spread, which does the opposite. Tidyr has a syntax generally more consistent with that of dplyr.