Re: [R] reordering a data.frame

From: Robin Hankin <r.hankin_at_noc.soton.ac.uk>
Date: Fri 06 May 2005 - 00:07:35 EST

Hi

R> d <-
data.frame(id=1:3,est0=c(1,10,100),est1=c(6,7,8),est2=c(-5,-5,-5))

R> d

   id est0 est1 est2

1  1    1    6   -5
2  2   10    7   -5
3  3  100    8   -5

R> out <- as.vector(t(d[,-1]))
R>
cbind(id=rep(d$id,each=nrow(d)),est=as.vector(row(as.matrix(d[, -1]))),out)

       id est out

  [1,]  1   1   1
  [2,]  1   2   6
  [3,]  1   3  -5
  [4,]  2   1  10
  [5,]  2   2   7
  [6,]  2   3  -5
  [7,]  3   1 100
  [8,]  3   2   8
  [9,]  3   3  -5

R>

Hope this helps

rksh

On May 6, 2005, at 02:26 pm, Achaz von Hardenberg wrote:

> 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@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@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
>
>

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

______________________________________________
R-help@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
Received on Fri May 06 00:28:43 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:36 EST