[R] reordering a data.frame

Liaw, Andy andy_liaw at merck.com
Thu May 5 16:02:32 CEST 2005


Use reshape(), as:

> dat
  id est0 est1 est2 est3 est4 est5 est6 est7
1  1    1    2    3    1    7    9    3    4
2  2    4    1    1    7    6    5    1    2
> dat2 <- reshape(dat, varying=list(names(dat)[-1]), times=0:7,
direction="long")
> dat2
    id time est0
1.0  1    0    1
2.0  2    0    4
1.1  1    1    2
2.1  2    1    1
1.2  1    2    3
2.2  2    2    1
1.3  1    3    1
2.3  2    3    7
1.4  1    4    7
2.4  2    4    6
1.5  1    5    9
2.5  2    5    5
1.6  1    6    3
2.6  2    6    1
1.7  1    7    4
2.7  2    7    2

Andy 

> From: Achaz von Hardenberg
> 
> Hi,
> I have a data.frame which looks like this:
>   
> id     est0     est1	est2	est3	est4	est5	est6    est7
>  1   	1	2	3	1	7	9	3	4
>  2	4	1	1	7	6	5	1	2  
> [...]
> 
> 
> I would like to reorder it to obtain the following:
> 
> id  	est	VALUE
> 1	0	1
> 1	1	2
> 1	2	3
> 1	3	1
> 1	4	7
> 1	5	9
> 1	6	3
> 1	7	4
> 2	0	4
> 2	1	1
> 2	2	1
> 2	3	7
> 2	4	6
> 2	5	5
> 2	6	1
> 2	7	2
> [...]
> 	
> Can anybody help me out?
> 
> Thanks in advance!
> 
> Achaz
> 
> 
> Achaz von Hardenberg
> --------------------------------------------------------------
> ------------------------
> Centro Studi Fauna Alpina - Alpine Wildlife Research Centre
> Parco Nazionale Gran Paradiso, via della Rocca 47, 10123 Torino, Italy
> 
> e-mail: fauna at pngp.it
> Tel. (office): +39.011.8606212
> Tel. (mobile): +39.328.8736291
> Fax: +39.011.8121305
> --------------------------------------------------------------
> ------------------------
> Open access to all papers published in the Journal of 
> Mountain Ecology:
> http://www.mountainecology.org
> 
> GSE-AIESG (Gruppo Stambecco Europa - Alpine Ibex European 
> Specialist Group):
> http://www.gseonline.org
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 
> 
>




More information about the R-help mailing list