Skip to content
Prev 4144 / 7420 Next

manipulating species matrices

Dear Kendra,
I am not sure I understand your question exactly. Maybe the R code you 
already have would help.

Below is a sample of the data as returned by dput() so that anyone can 
follow or extend this reply.

First, I would create a variable distinguishing all levels, for which 
the mean is to be calculated:
env$site.horizon<- paste(env$site, env$horizon, sep= '.')

Now, aggregate(), as you write, may be used to calculate mean 
abundances for every site/horizon category (level). Note that only 
samples where om == 0 are used for the calculation:
Means<- aggregate(spe[env$om == 0,], by= list(env$site.horizon[env$om 
== 0]), FUN= mean)

The following just makes rownames from the first column, so that one 
may use them in a name subscript to select desired rows.
Means.dtf<- data.frame(Means, row.names=1)

This dataframe now contains the mean values for every species and every 
site/horizon combination,
and may be extended by the name subscript to the dimensions of the 
original species dataframe:
Means.extended<- Means.dtf[env$site.horizon,]

This is probably what you want to divide the species counts with:
spe.divided<- spe / Means.extended

NaN (0/0) and Inf (0/anything) values will emerge, these can be changed 
to something meaningful:

spe.div[is.na(spe.div)]<- 0 # or anything you want
spe.div[spe.div==Inf]<- 0 # or anything you want

Hope that helps,
Vit

... and the data:
env<- structure(list(site = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L
), .Label = "A7", class = "factor"), om = c(2L, 2L, 3L, 3L, 1L,
1L, 2L, 2L, 3L, 3L, 1L, 1L, 2L, 2L, 3L, 3L, 1L, 1L, 0L, 0L, 0L,
0L, 0L), horizon = c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 2L), site.horizon = 
c("A7.1",
"A7.2", "A7.1", "A7.2", "A7.1", "A7.2", "A7.1", "A7.2", "A7.1",
"A7.2", "A7.1", "A7.2", "A7.1", "A7.2", "A7.1", "A7.2", "A7.1",
"A7.2", "A7.2", "A7.1", "A7.2", "A7.1", "A7.2")), .Names = c("site",
"om", "horizon", "site.horizon"), row.names = c("A7001", "A7002",
"A7003", "A7004", "A7007", "A7008", "A7009", "A7010", "A7011",
"A7012", "A7015", "A7016", "A7019", "A7020", "A7021", "A7022",
"A7023", "A7024", "A7026", "A7027", "A7028", "A7029", "A7030"
), class = "data.frame")


spe<- structure(list(Otu00209 = c(4L, 0L, 8L, 1L, 9L, 1L, 31L, 3L,
3L, 6L, 13L, 1L, 7L, 3L, 13L, 0L, 23L, 4L, 0L, 0L, 2L, 17L, 13L
), Otu00358 = c(95L, 8L, 156L, 34L, 9L, 8L, 9L, 1L, 1L, 1L, 4L,
0L, 0L, 2L, 3L, 8L, 3L, 10L, 0L, 0L, 1L, 8L, 0L), Otu00359 = c(1L,
0L, 0L, 0L, 6L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 1L, 0L, 1L, 0L), Otu00388 = c(0L, 0L, 4L, 1L, 3L, 0L,
0L, 1L, 0L, 3L, 9L, 1L, 2L, 27L, 0L, 1L, 0L, 1L, 1L, 0L, 6L,
2L, 0L), Otu00389 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), Otu00533 = c(7L,
0L, 3L, 0L, 21L, 3L, 0L, 1L, 6L, 13L, 0L, 1L, 2L, 2L, 1L, 0L,
2L, 2L, 5L, 0L, 0L, 2L, 1L), Otu00608 = c(1L, 1L, 3L, 4L, 0L,
0L, 9L, 1L, 2L, 0L, 0L, 32L, 13L, 1L, 58L, 3L, 27L, 6L, 0L, 0L,
0L, 3L, 0L), Otu00618 = c(0L, 0L, 0L, 91L, 0L, 10L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), Otu00669 = 
c(1L,
0L, 0L, 0L, 8L, 0L, 4L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L,
0L, 0L, 0L, 0L, 0L, 0L), Otu00695 = c(0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L), Otu00696 = c(4L, 0L, 3L, 1L, 1L, 0L, 1L, 2L, 0L, 2L, 3L,
0L, 2L, 0L, 0L, 0L, 1L, 3L, 1L, 7L, 1L, 19L, 0L), Otu00706 = c(0L,
0L, 0L, 0L, 2L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 2L, 0L), Otu00725 = c(0L, 0L, 0L, 3L, 1L, 0L,
0L, 0L, 0L, 0L, 1L, 0L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L), Otu00761 = c(0L, 4L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 1L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L)), .Names = 
c("Otu00209",
"Otu00358", "Otu00359", "Otu00388", "Otu00389", "Otu00533", "Otu00608",
"Otu00618", "Otu00669", "Otu00695", "Otu00696", "Otu00706", "Otu00725",
"Otu00761"), class = "data.frame", row.names = c("A7001", "A7002",
"A7003", "A7004", "A7007", "A7008", "A7009", "A7010", "A7011",
"A7012", "A7015", "A7016", "A7019", "A7020", "A7021", "A7022",
"A7023", "A7024", "A7026", "A7027", "A7028", "A7029", "A7030"
))


Dne 2013-10-28 22:27, Mitchell, Kendra napsal: