s-news
[Top] [All Lists]

Re: loop question

To: <s-news@lists.biostat.wustl.edu>
Subject: Re: loop question
From: "Chushu Gu" <chushugu@hotmail.com>
Date: Sun, 28 Sep 2003 15:41:28 -0700
Hi all
 
Here ia my function
 
opo<-function(pop, agelimit)
{
 qc <- rep(0.1,agelimit)
 death <- rep(0, agelimit)
 for(i in 1:pop){
    result<-unit.death(agelimit,qc)
    death <- death+result
}
 return(death)
}
 
 unit.death <- function(agelimit, qc)
 {
  temp <- runif(agelimit)
  temp <- temp - qc
  return(as.integer(temp == temp[which(temp < 0)[1]]))
  }
 

opo(1000000,110)
 
The program is dead due to a lot of loops
Is there any way to get rid of the for loop and let the program fast?
 
Thanks
 
Chushu Gu
<Prev in Thread] Current Thread [Next in Thread>
  • Re: loop question, Chushu Gu <=