I am looking to take data that is currently wide and melt it into a long format. The trick is that I want to create a sequence indicator.
Here are my data:
df.wide <- data.frame(id = 1:5,
code1 = sample(month.abb, 5),
code2 = sample(month.abb, 5))
What I am looking for:
id rank value
1 1 1 Dec
2 1 2 Jan
3 2 1 May
4 2 2 Jun
5 3 1 Aug
6 3 2 Aug
7 4 1 Sep
8 4 2 Mar
9 5 1 Dec
10 5 2 Nov
I suspect that I could use this:
melt(df.wide, id=c("id"))
and iterate over the data aftewards to clean up the results, but I know reshape is a great package and wanted to ask before I reinvent the wheel.
Here is a one-liner using the
reshapefunction inbaseR (not to be confused with thereshapepackage)