[R-sig-eco] R-Sig Eco- Looking for help with R code to calculte fish metrics using 2 tables

syrovat at sci.muni.cz syrovat at sci.muni.cz
Wed Feb 8 15:12:58 CET 2012


Hi Alison,
Do I understand well you are interested in the number (or proportion) of
fish that have the particular trait per site?
In that case you can use matrix multiplication. For example:

# example data
set.seed(0)
spe<- matrix(rpois(15,3), ncol=3)
dimnames(spe)<- list(paste('site',1:5,sep=''), paste('spe',1:3,sep=''))
set.seed(0)
traits<- matrix(sample(c(T,F), 6, replace=T), ncol=2)
dimnames(traits)<- list(paste('spe',1:3,sep=''), paste('trait',1:2,sep=''))

# calculate counts of fish per trait and site
spe %*% traits

# proportions
spe %*% traits / rowSums(spe)

Just make sure your species are in the same order in both matrices.
Cheers,
Vit


> Hello All,
>
> I am looking for help finding R code to help me generate fish indices of
> stream quality.? A brief over view of what I currently have:? I am using
> two different data sets to help generate these metrics.? The first one
> consists of site data, where each row is a sampling event and each column
> is a species, with the corresponding cells containing abundances for that
> site.? The second data set is a fish traits database where each row is a
> fish species (same species as the sampling events) and each column is a
> specific trait with each cell indicating whether the fish species has that
> trait or not.? Specifically, I'm looking for code that will help me read
> from both tables at once, with out me having to write a bunch of if-then
> statements.
>
> Any help, or ideas on a starting point, would be greatly appreciated.
>
> Thanks,
>
> Alison Anderson
>
> --
> Alison M. Anderson
> Graduate Research Assistant
> West Virginia University
> aander16 at mix.wvu.edu
> (419)305-4167
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>



More information about the R-sig-ecology mailing list