doubt in generating loops with For
Hi Thiago, I am not familiar with the diversity measure you are trying to calculate and your example code is not complete - one can not simulate your comm and dist objects. But at the first sight one can see that in your loop you are trying to select columns 1, 2, 3,... 1000 from the comm matrix, which probably has only 10 columns (if sites are in columns and species in rows, contrary to how such data are traditionally stored). for(z in 1:10) instead of for(z in 1:1000) should do the job. Vit Dne 2015-04-15 23:24, Thiago A. Pires napsal:
Hi guys,
I have a question when trying to generate 1000 measures with "for"
function. For example, I have 10 locations with 5 species , and I want
to
apply a diversity measure on each site. But when I try to run one is
with
my function, I can not, I get an error message: "Error in com[, z] :
subscript out of bounds", and I think it should be a simple mistake,
but
I'm not seeing. If you guys can help with it, I would appreciate. Right
below is an example for my code:
comm= a community matrix with 10 sites and 5 species
dist= a pairwise distance-based matrix of species
?
? for (z in 1:1000)
{
func.sim[z,]<- (t(comm[, z]) %*% (as.matrix(dist)^2) %*%
comm[, z])/2/(sum(comm[, z])^2)?
}
?Error in comm[, z] : subscript out of bounds?
?Best regards,
Thiago.?
_____________________________________________________________ *Thiago A. Pires* Ph.D. student in Ecology - Instituto de Biologia - UNICAMP Collaborator Researcher - Laborat?rio de Ecologia e Sistem?tica - UNIFESP Email: pires.thiagoaugusto at gmail.com / Skype: thiago.augusto.pires Home Page: http://thiagoaugustopires.wix.com/naturevisions CV Lattes: http://buscatextual.cnpq.br/buscatextual/visualizacv.do?id=K4298681Z0 _____________________________________________________ [[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