Try the reshape2 package. You will probablly have to install the package.  
install.packages("reshape2)

with your data as xx :
library(reshape2)
melt(xx, id =c("Year", "Route", "Point"))

seems to do what you want.

John Kane
Kingston ON Canada


> -----Original Message-----
> From: agoij...@cnia.inta.gov.ar
> Sent: Sat, 6 Oct 2012 08:03:11 -0700 (PDT)
> To: r-help@r-project.org
> Subject: [R] Presence/ absence data from matrix to single column
> 
> I've been trying to reshape this database but haven't succeed at it. I
> tried
> using loops but can't get it right. I just want to reshape my database
> from
> this matrix, to the one below, with only one column of data.
> 
> Year  Route   Point   Sp1     Sp2     Sp3
> 2004  123     123-1   0       1       0
> 2004  123     123-2   0       1       1
> 2004  123     123-10  1       1       0
> 
> What I want:
> 
> Year  Route   Point
> 2004  123     123-1   Sp1     0
> 2004  123     123-2   Sp1     0
> 2004  123     123-10  Sp1     1
> 2004  123     123-1   Sp2     1
> 2004  123     123-2   Sp2     1
> 2004  123     123-10  Sp2     1
> 2004  123     123-1   Sp3     0
> 2004  123     123-2   Sp3     1
> 2004  123     123-10  Sp3     0
> 
> 
> 
> 
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Presence-absence-data-from-matrix-to-single-column-tp4645271.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> 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.

____________________________________________________________
Share photos & screenshots in seconds...
TRY FREE IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if1
Works in all emails, instant messengers, blogs, forums and social networks.

______________________________________________
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.

Reply via email to