Thanks a lot Joris, that worked wonderfully!

Another solution which a colleague at the department came up with was 
this, which avoids curly brackets, which some people may or may not be 
frightened by...

##matrices
bank.plot<-matrix(,5,3,dimnames=list(c("AB 01 01", "AB 01 02", "AB 02 
01","AB 03 01","AB 03 02"),c(1:3)))
site.veg<-matrix((c(1,0,1,1,0,1,0,1,1)),3,3,dimnames=list(c("AB 01", "AB 
02", "AB 03")))

##create matrix where sites correspond to plots
bank.veg<-cbind(rownames(bank.plot),(substr(rownames(bank.plot),1,5)))

##create new site x species matrix, and change the rownames to 
correspond with the plots
site.dupl<-site.veg[bank.veg[,2],]
rownames(site.dupl)<-rownames(bank.plot)


Alistair


Joris Meys wrote:
> Hi Alistair,
>
> ?match will help, but you need to extract the site names first. Quick 
> and dirty :
>
> seed <- substr(rownames(bank.plot),1,5)
> site <- rownames(site.veg)
>
> for(i in 1:length(seed)){
>   bank.plot[i,]<-site.veg[match(seed[i],site),]
> }
>
> Cheers
> Joris
> On Wed, May 26, 2010 at 2:50 PM, Alistair Auffret 
> <alistair.auff...@natgeo.su.se <mailto:alistair.auff...@natgeo.su.se>> 
> wrote:
>
>     Hello all,
>     I am going slightly mad trying to create a table for running
>     co-correspondence analysis.
>
>     What I have is seed bank and vegetation data, and my aim  is to
>     see if the vegetation found in a site (containing several seed
>     bank samples) can predict the composition of a seed bank sample
>     within that site. So for this I need two tables with matching rows.
>
>     I have created an empty matrix, where the rows correspond to the
>     seed bank samples
>
>     bank.plot<-matrix(,5,3,dimnames=list(c("AB 01 01", "AB 01 02", "AB
>     02 01","AB 03 01","AB 03 02"),c(1:3)))
>     bank.plot
>
>     And I have a matrix where I have presence/absence of species in
>     the vegetation at each site.
>
>     site.veg<-matrix((c(1,0,1,1,0,1,0,1,1)),3,3,dimnames=list(c("AB
>     01", "AB 02", "AB 03")))
>     site.veg
>
>     Is there a way to fill the bank.plot matrix with the results from
>     the vegetation survey, duplicating them appropriately to match
>     sites to plots, even when the number or sites per plot are
>     unequal? i.e. in my example, the row AB 01 in site.veg would be
>     duplicatied for the first two rows, AB 02 only once, and AB 03 twice.
>
>     Hope you can help!
>
>     Many thanks.
>
>
>     -- 
>
>     Alistair Auffret
>     PhD Student
>
>     Department of Physical Geography and Quaternary Geology
>     Stockholm University
>     106 91 Stockholm
>     Sweden
>
>     +46(0)8 674 7568
>     +46(0)76 7158975
>
>     ______________________________________________
>     R-help@r-project.org <mailto: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.
>
>
>
>
> -- 
> Joris Meys
> Statistical Consultant
>
> Ghent University
> Faculty of Bioscience Engineering
> Department of Applied mathematics, biometrics and process control
>
> Coupure Links 653
> B-9000 Gent
>
> tel : +32 9 264 59 87
> joris.m...@ugent.be
> -------------------------------
> Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php

-- 

Alistair Auffret
PhD Student

Department of Physical Geography and Quaternary Geology
Stockholm University
106 91 Stockholm
Sweden

+46(0)8 674 7568
+46(0)76 7158975

        [[alternative HTML version deleted]]

______________________________________________
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