Try this:
DF <- data.frame(para.A = c(1, 3), para.B = c(2, 4), para.C = c(3, 1),
obs1 = c(4, 1), obs2 = c(5, 0), obs3 = c(7, 8))
long <- reshape(DF, direction = 'long', varying=4:6, sep =
"")
long[order(long$id),]
On Mon, Jun 15, 2009 at 4:02 PM, Oliver <fwang2@gmail.com> wrote:
> hi, all
>
> I inherited a data set with format like the following:
>
> para.A para.B para.C observation.1 observation.2 observation.3
> ....
>
> Essentially, the same experiment (with same parameters) are conducted
> 3 times, with corresponding observations.
>
> What are the efficient ways of re-arranging this data set in a one row
> per observation such that:
>
> para.A para.B para.C observation.1
> para.A para.B para.C observation.2
> para.A para.B para.C observation.3
>
> I am thinking of doing a loop on each row and expand it, but wondering
> if there are other more convenient ways?
>
> thanks
>
> Oliver
>
> ______________________________________________
> R-help@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.
>
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O
[[alternative HTML version deleted]]