I have a data frame that looks like this, with two key columns and then a count of things that come in three different types.
Year Month Urban Suburban Rural
1 1 1 11 12 13
2 1 2 21 22 23
I want to expand each row so that it lists the type as a factor and then the number in that type, so something like this:
Year Month Type Number
1 1 1 Urban 11
2 1 1 Suburban 12
3 1 1 Rural 13
4 1 2 Urban 21
5 1 2 Suburban 22
6 1 2 Rural 23
is there a function that does this painlessly?
This is precisely what the
reshapeandreshape2packages are designed to do:There is a paper in the journal of statistical software that’s a great place to get started.