I have trouble reshaping a data frame.
Here is a sample data set:
u<-data.frame(patient=1:9,time=1:3,var1=rnorm(9),var2=rnorm(9),var3=rnorm(9),var5=rnorm(9),var6=rnorm(9))
Instead of 6, I have 20 variables.
This only thing I want, is to make this wide data set into a long data set. Also, I have been searching on Stack Overflow/Google how to do this, but unsuccessful. Most reshape questions posted here seem way more difficult then what I am after.
What I am after is:
patient time variable value
1 1 var1 1.70484636
2 2 var1 0.19637999
3 3 var1 -1.20419038
4 1 var1 0.06944788
5 2 var1 -1.03074549
6 3 var1 0.9396862
7 1 var1 -0.57904879
8 2 var1 1.16163798
9 3 var1 1.11314472
1 1 var2 0.2138141
2 2 var2 2.9763986
3 3 var2 0.9686543
4 1 var2 0.1321531
5 2 var2 0.844687
6 3 var2 1.1336502
7 1 var2 0.5902222
8 2 var2 1.392971
9 3 var2 1.5335116
1 1 var3 0.93968 62
2 2 var3 2.9763986
3 3 var3 0.844687
....