I have data in the following format, with Variables, data by years and where A, B, C, D are the row id's.
Variable 1 blank column Variable 2
2008 2009 2010 2011 2008 2009 2010 2011
A 1 5 9 13 5 10 15 20
B 2 6 10 14 25 30 35 40
C 3 7 11 15 45 50 55 60
D 4 8 12 16 65 70 75 80
I would like to get it in this format:
Variable Year Data
A Variable1 2008 1
A Variable1 2009 5
.....
.....
D Variable2 2010 75
D Variable2 2011 80
I thought of using gather from library(tidyr) but I cant figure out how to do it. Sorry do not have a reproducible example.
structure(list(X1 = c(NA, "A", "B", "C", "D"), Variable1 = c(2008,
1, 2, 3, 4), X3 = c(2009, 5, 6, 7, 8), X4 = c(2010, 9, 10, 11,
12), X5 = c(2011, 13, 14, 15, 16), Variable1 = c(2008, 5, 25,
45, 65), X7 = c(2009, 10, 30, 50, 70), X8 = c(2010, 15, 35, 55,
75), X9 = c(2011, 20, 40, 60, 80)), .Names = c("X1", "Variable1",
"X3", "X4", "X5", "Variable1", "X7", "X8", "X9"), row.names = c(NA,
5L), class = "data.frame")