I am working with a wide data set that looks like this:
library( tibble )
wide_data <- data_frame(month_1 = c("Jan", "Feb", "Mar", "Jun"),
score_1 = c(4, 5, 6, 4),
month_2 = c("Jan", "Mar", NA, NA),
score_2 = c(3, 2, NA, NA),
month_3 = c("Feb", "Mar", "Jun", NA),
score_3 = c(8, 7, 4, NA))
I would like to produce the following:
id month score
1 Jan 4
1 Feb 5
1 Mar 6
1 Jun 4
2 Jan 3
2 Mar 2
3 Feb 8
3 Mar 7
3 Jun 4
Note that the months in the initial data set do not line up across observations. What's the best way to 'tidy' this up? Should I just read the underlying data into R two columns at a time and bind_rows? If so, what's the most elegant way to go about that?