r/R_Programming • u/snicksn • 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
View all comments
Show parent comment
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.