我想显示在生存的宿主中有多少内共生体,正如我的宿主矩阵中的最后一个时间步骤所指示的。最终时间步骤中的endos矩阵中的相应列将相加在一起,以表示各自幸存的主机。如果有人对如何显示这一点有想法,请告诉我!到目前为止,我的代码如下:
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)
}
}发布于 2014-03-11 20:20:07
要找到宿主幸存者,你可以:
survivors = unique(hosts[time+1, ])它将移除幸存者载体中的副本。然后,你可以在幸存者中索引endos的数量。我假设您对endos的动态与生存无关,所以您可以这样做:
endosInSurvivors = endos[time+1, survivors]若要通过最后一步主机的id计算endos之和,可以使用
tapply(endos[time+1, ], INDEX=hosts[time+1, ], FUN=sum) # using set.seed(1234)
2 7
79 38 https://stackoverflow.com/questions/22314699
复制相似问题