Skip to content
Prev 4996 / 7420 Next

doubt in generating loops with For

Hi V?t,

Thank you for your quick response. Indeed, I did not put all the code,
because I thought it would mess up more than help. But I'll put here the
full code. I realized the issue of columns, I had come to this conclusion
also. However, I would like to generate a "random" matrix of  community
based in a "real" community  in every loop, and likewise, generating a
diversity measure of these communities, also in each loop. If you can help
me with this question , I'd appreciate.

Code:

require (vegan)

comm<-t(data.frame(sp1=rpois(10, 1), sp2=rpois(10,1), sp3=rpois(10,1),
                       sp4=rpois(10,1), sp5=rpois(10,1)))

traits<-t(data.frame(sp1=rnorm(5,1.2,.2),sp2=rnorm(5,2,.5),
                     sp3=rnorm(5,3,.3), sp4=rnorm(5,0.5,.2),
sp5=rnorm(5,.9,.6)))

dist<-vegdist(traits,"gower")
comm<-as.matrix(comm)
func.sim<-data.frame(rep(NA, 1000))

 for (z in 1:1000)
  {
  comm1<-apply(comm,2,sample)
  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
_____________________________________________________





2015-04-16 4:40 GMT-03:00 V?t Syrov?tka <syrovat at sci.muni.cz>: