Ill try this one as well.
And I guess the one below is not going to work, because all my species
have different names.
Thanks!
#nms <- names(adat)
nms <- c("Year", "Route", "Point", paste0("Sp", 1:250))
pattern <- "^Sp[[:digit:]]+$"
whichCols <- grep(pattern, nms)
whichNames <- nms[whichCols]
reshape(..., varying = whichCols, times = whichNames, ...)
On Sun, Oct 7, 2012 at 3:02 PM, arun <[email protected]> wrote:
> Hi,
> I guess you are not talking about the melt() method.
> dat1<-read.table(text="
> 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
> ",header=TRUE,sep="",stringsAsFactors=FALSE)
>
>
> #If all the Sp columns are located next to another as shown in your
> example dataset, then you can also try this:
> name1<-unlist(strsplit(paste(colnames(dat1)[4:6],collapse=" ")," "))
> reshape(dat1,varying=4:6,v.name
> ="Sp-value",times=name1,timevar="Sp-name",idvar=c("Year","Route","Point"),direction="long")
>
> A.K.
>
>
>
>
>
>
> ----- Original Message -----
> From: Rui Barradas <[email protected]>
> To: agoijman <[email protected]>
> Cc: [email protected]
> Sent: Sunday, October 7, 2012 2:32 PM
> Subject: Re: [R] Presence/ absence data from matrix to single column
>
> Hello,
>
> I haven't been following this thread but apparently the answer to your
> worries is no.
> You can use a combination of names() and grep() to sort it out.
> something like
>
> #nms <- names(adat)
> nms <- c("Year", "Route", "Point", paste0("Sp", 1:250))
>
> pattern <- "^Sp[[:digit:]]+$"
> whichCols <- grep(pattern, nms)
> whichNames <- nms[whichCols]
>
> reshape(..., varying = whichCols, times = whichNames, ...)
>
>
> Hope this helps,
>
> Rui Barradas
> Em 07-10-2012 15:35, agoijman escreveu:
> > The problem with that, is that I just wrote an example of my database,
> but I
> > have around 250 species and more than 500 sites. In the approach you show
> > me, it looks like I have to enter every species name and sites
> individually,
> > right?
> >
> >
> >
> > --
> > View this message in context:
> http://r.789695.n4.nabble.com/Presence-absence-data-from-matrix-to-single-column-tp4645271p4645331.html
> > Sent from the R help mailing list archive at Nabble.com.
> >
> > ______________________________________________
> > [email protected] 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.
>
> ______________________________________________
> [email protected] 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.
>
>
--
---
Lic. Andrea Paula Goijman
Grupo Ecología y Gestión Ambiental de la Biodiversidad
IRB - INTA Castelar, Argentina
[email protected]
<http://inta.gob.ar/personas/goijman.andrea/>
http://inta.gob.ar/personas/goijman.andrea/
PhD Candidate
Georgia Cooperative Fish and Wildlife Research Unit
D.B. Warnell School of Forestry and Natural Resources
University of Georgia
Athens, GA 30602 USA
Tel. +706.206.4805
[email protected]
[[alternative HTML version deleted]]
______________________________________________
[email protected] 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.