By the following condition:
ifelse(??, 1, Z/(1+1))
What to put in place of "??" so that R understands that when i = j in the matrix Z, I want to assign the value 1?
By the following condition:
ifelse(??, 1, Z/(1+1))
What to put in place of "??" so that R understands that when i = j in the matrix Z, I want to assign the value 1?
I do not see a simple way of solving your question. But I propose two forms of resolution:
Assign the desired value to the diagonal, directly.
a <- matrix(rep(0,100), nrow = 10)
diag(a) <- 1
Analyze the position to assign the value.
a <- matrix(rep(0,100), nrow = 10)
for(i in 1:dim(a)[1]){
for(j in 1:dim(a)[2]){
if(i == j){
a[i,j] <- 1
}
}
}