[R] Can't get the correct order from melt.data.frame of reshape library.

From: Daren Tan <daren76_at_hotmail.com>
Date: Sat, 26 Jul 2008 16:00:20 +0000

Simple illustration,  

> df3 <- data.frame(id=c(3,2,1,4), age=c(40,50,60,50), dose1=c(1,2,1,2), dose2=c(2,1,2,1), dose4=c(3,3,3,3))> df3 id age dose1 dose2 dose41 3 40 1 2 32 2 50 2 1 33 1 60 1 2 34 4 50 2 1 3> melt.data.frame(df3, id.var=1:2, na.rm=T) id age variable value1 3 40 dose1 12 2 50 dose1 23 1 60 dose1 14 4 50 dose1 25 3 40 dose2 26 2 50 dose2 17 1 60 dose2 28 4 50 dose2 19 3 40 dose4 310 2 50 dose4 311 1 60 dose4 312 4 50 dose4 3
 

My objective is to get the below such that the "long" form is in the same order as the "id" column of df3.

   id age variable value1   3  40    dose1     12   3  40    dose2     2
3   3  40    dose4     3
4   2  50    dose1     25   2  50    dose2     1
6   2  50    dose4     3
7   1  60    dose1     18   1  60    dose2     2
9   1  60    dose4     3
10   4  50    dose1     211   4  50    dose2     112  4  50    dose4     3
_________________________________________________________________


	[[alternative HTML version deleted]]

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sat 26 Jul 2008 - 16:05:23 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 26 Jul 2008 - 19:32:31 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive