Hi all, I have a population in which I want to follow living and dead animals through time ( 1 simulation, 100 years). I have created 2 arrays for living and dead animals In the starting population there are, say, 500, animals To determine whether each of these animals survives to a following age-class, a uniformal chance is generated, resulting in "TRUE" if the animal lives, or "FALSE" if it dies Live.Animals <- array (FALSE, c(MaxAnimals, Years)) Dead.Animals <- array (FALSE, c(MaxAnimals, Years)) MaxAnimals <- 5000 ## max animals in the pop. Years <- 100 ## years in the simulation Live.Animals[,yy] <- ifelse ((runif(MaxAnimals,0,1) < sur.age) & Live.Animals[,yy-1], TRUE, FALSE) ## Live.Animals [,yy-1] : Animal had to be alive the year before ## sur.age : survival of each age class Now, the array LiveAnimals is filled throughout the years with more and more animals surviving( "TRUE") (and being born but those formulae are not in this post) My question is : How do I arbitrarily assign the animals being "FALSE" ***according to the uniformal chance generation*** to the array Dead.Animals, there being "TRUE"? Thanks in advance! -- View this message in context: http://www.nabble.com/Population-model-question-tp14833982p14833982.html Sent from the R help mailing list archive at Nabble.com.
-Halcyon- wrote:> > My question is : How do I arbitrarily assign the animals being "FALSE" > ***according to the uniformal chance generation*** to the array > Dead.Animals, there being "TRUE"? >Maybe I'm missing something, but aren't dead animals just the ones that aren't alive? Why do you even need the Dead.Animals array if you filled Live.Animals correctly? ## 4 animals in cohort and 3 years Live.Animals<-matrix(c(T,T,F, T,T,T, T,T,F, F,F,F), nrow=4, byrow=TRUE) Live.Animals [,1] [,2] [,3] [1,] TRUE TRUE FALSE [2,] TRUE TRUE TRUE [3,] TRUE TRUE FALSE [4,] FALSE FALSE FALSE # Dead animals are NOT Live.Animals? !Live.Animals [,1] [,2] [,3] [1,] FALSE FALSE TRUE [2,] FALSE FALSE FALSE [3,] FALSE FALSE TRUE [4,] TRUE TRUE TRUE # or maybe use rowSums to find dead animals dead<- which(rowSums(Live.Animals) < 3) [1] 1 3 4 Chris -- View this message in context: http://www.nabble.com/Population-model-question-tp14833982p14848821.html Sent from the R help mailing list archive at Nabble.com.