Hi

I want to write a C function for the R Code below and call it with .Call:

SimPoisson <- function(lambda,tgrid,T2M)
#Simulation eines Poissonprozesses
{
        NT <- 0
        Ni <- rep(0,length(tgrid))
        tau <- 0
        sign <- 0
        if(lambda != 0)
        {
                i=1
                j=1
                while (1)
                {
                        EVar <- rexp(1,lambda)
                        sign <- sign + EVar
                        if (sign > T2M)
                        {
                                break
                        }
                        tau[i] <- sign
                        i = i+1
                        for (j in j:length(tgrid))
                        {
                                if (tgrid[j] < sign)
                                {
                                        Ni[j] <- NT
                                }else
                                {
                                        break
                                }
                        }
                        NT <- NT + 1
                }
                for (j in j:length(tgrid))
                {
                        Ni[j] <- NT
                }
        }
        return(list(NT=NT,Ni=Ni,tau=tau))
}

I read the manual "writing R extensions" over and over again, but i have
no idea, how to solve the problem with tau because i dont no the length
of tau at the begining of the function

Fabian

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to