Re: [R-sig-eco] Re-arrange data frame

2012-06-29 Thread David Valentim Dias
ecology-boun...@r-project.org [mailto: > r-sig-ecology-boun...@r-project.org] On Behalf Of Baldwin, Jim -FS > Sent: Friday, June 29, 2012 10:28 AM > To: Peter Solymos; Manuel Spínola > Cc: r-sig-ecology@r-project.org > Subject: Re: [R-sig-eco] Re-arrange data frame > > Here is a

Re: [R-sig-eco] Re-arrange data frame

2012-06-29 Thread Baldwin, Jim -FS
AM To: Peter Solymos; Manuel Spínola Cc: r-sig-ecology@r-project.org Subject: Re: [R-sig-eco] Re-arrange data frame Here is an alternative approach that takes a few more steps and assumes the original data frame is named d0: # Split into two data frames d1 <- d0[,c(1:3)] d2 <- d0[,c(1,4,5)

Re: [R-sig-eco] Re-arrange data frame

2012-06-29 Thread Baldwin, Jim -FS
[mailto:r-sig-ecology-boun...@r-project.org] On Behalf Of Peter Solymos Sent: Friday, June 29, 2012 9:45 AM To: Manuel Spínola Cc: r-sig-ecology@r-project.org Subject: Re: [R-sig-eco] Re-arrange data frame Manuel, You haven't specified the general problem, but for this particular situation th

Re: [R-sig-eco] Re-arrange data frame

2012-06-29 Thread Peter Solymos
Manuel, You haven't specified the general problem, but for this particular situation this is how you can do it: x <- data.frame(array(1:12, c(3,4), list(paste("item", 1:3), paste("col", 1:4 x <- data.frame(Item=rownames(x), x) y <- data.frame(Item=x$Item[rep(1:3, each=2)], matrix(as.matrix(x[

[R-sig-eco] Re-arrange data frame

2012-06-29 Thread Manuel Spínola
Dear List members, How can I re-arrange a data frame as detailed below. old data frame Item col1 col2 col3 col4 item1 12116 7 item2 108 5 4 item3 3 5 4 3 New data frame item1 12 11 item1 6 7 item2 108 item2