I am new to coding and I am currently looking at an R code that I found online. The full code can be found at this link: http://epirecip.es/epicookbook/chapters/kr08/3_4/r_desolve
I am trying to understand the language a bit better, so I had a few questions about this portion of the code here:
# differential equations
diff_eqs <- function(times, Y, parms){
dY <- numeric(length(Y))
with(parms,{
# creates an empty matrix
for(i in 1:m){
dY[i] <- nu[i]*n[4] - beta[,i]%*%Y[2*m + seq(1:m)] * Y[i] - mu[i] * Y[i] # S_i
dY[m+i] <- beta[,i] %*% Y[2*m + seq(1:m)] *Y[i] - mu[i] * Y[m+i] - sigma * Y[m+i] #E_i
dY[2*m+i] <- sigma * Y[m+i] - gamma * Y[2*m + i] - mu[i] * Y[2*m+i] #I_i
dY[3*m+i] <- gamma * Y[2*m+i] - mu[i] * Y[3*m + i] #R_i
}
list(dY)
})
}
In R, what does [,i]
mean? And what is the difference between say [,i]
and [i]
in the context of this system of of equations?
question from:
https://stackoverflow.com/questions/65849389/what-does-i-do-in-r 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…