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 5069How 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
2
u/snicksn Jul 10 '16 edited Jul 10 '16
I find that:
Also works (but you get two extra columns, $ind and $ind.1) But the simplest should be just saying column one should have the values of row one:
But it does not work:
and I guess thats why the stacking is needed. I am curious how R keep track of different types, like I guess R knows if its a column or row? Sometimes I feel it might be easier to just manipulate text with loops.. but I guess thats due to my ignorance.
Thanks