I did not look at your code in detail, but I see a potential problem in your
inner loop.  I think you intended k to be in 2,3,...N+1.  What you get from
your code is (2:N)+1 according to the operator precedence rules.  You need
2:(N+1).

HTH,
-Christos 

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Eric Blabac
Sent: Thursday, April 27, 2006 11:28 AM
To: [email protected]
Subject: [R] random walk on graph

Hi all,
I'm having issues coding a random walk on a fully connected, undirected
graph G with probability transition matrix P = (p_ij). Here is what I have
so far ...

for(i in 1:n){
        for(m in 1:M){
                x <- as.vector(matrix(rep(0,N+1),nc=N+1))
                x[1] <- i

                for(k in 2:N+1){
                        y <- as.vector(matrix(rep(0,n),nc=n))
                        r <- runif(1)
                        c <- c(0,cumsum(P[x[k-1],]))

                        for(j in 1:n){
                                y[j] <- (r >= c[j] & r < c[j+1])
                        }
                        x[k] <- which(y == 1)
                }
                L[i,m] <- x[N+1]
        }
}

its giving me the error:

Error in "[<-"(`*tmp*`, k, value = integer(0)) :
        nothing to replace with

no matter what I do I cant fix it ... any suggestions ?
Thanks

Eric Blabac
PhD Student - ASU Dept of Mathematics/Statistics

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to