matrix - Connecting matrices in R -


i show how many endosymbionts present in surviving hosts indicated final timestep in hosts matrix. corresponding columns in endos matrix @ final timestep added represent respective surviving hosts. if has thoughts on how show please let me know! here code far:

set.seed(123) time  <-10  hosts <-matrix(na,nrow=(time+1),ncol=10)  endos <-matrix(na,nrow=(time+1),ncol=10) hosts[1,] <- seq(1,10) endos[1,] <- rep(10,10)  for(tt in 1:time) {    indexhost <- sample(1:10,size=10,replace=true,prob=null)   hosts[tt+1,] = hosts[tt,indexhost]    for(indexhost in 1:10) {     endos[tt+1,indexhost]<-rbinom(1,(2*endos[tt,indexhost]),0.5)    }  } 

to find host survivors, can do:

survivors        = unique(hosts[time+1, ]) 

which remove duplicates in survivor vector. then, can index number of endos in survivors. i'm assuming dynamics endos independent of survivorship, can do:

endosinsurvivors = endos[time+1, survivors] 

to calculate sum of endos id of host @ last time step, can use

tapply(endos[time+1, ], index=hosts[time+1, ], fun=sum) # using set.seed(1234)   2  7  79 38  

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -