- #1
user366312
Gold Member
- 89
- 3
- TL;DR Summary
- Kindly explain the highlighted lines.
R code:
#==================================================================
# Build the transition matrix for random walk on n-cycle
#------------------------------------------------------------------
n <- 25 # we are creating (nXn) transition matrix
r1 <- c(0, 1/2, rep(0,n-3), 1/2) # create same values 22 times...
tmat <- matrix(0, nrow=n, ncol=n) # create a 0-matrix
tmat[1,] <- r1 # inject values in 'r1' into 'tmat' along the 1st row
for (i in 1:(n-1))
{
tmat[26-i,] <- r1[1 + (i:(n+i-1)) %% n] # ? mod operator
}
#=================================================================
What are being done in line#11?
How are elements being selected using mod operator?