I have this matrix in R, called MRASTI genereatet from the command
MRASTI <- matrix(sample(data.matrix(pune, rownames.force=NA),
22000, replace=TRUE),
nrow=1000, byrow=TRUE)
and i have this interval
x[(x>14274.19)&(x<14458.17)]
which is a vector with 9998 elements. I want to calculate this formula:
y <- 1 / length(MRASTI) * sum((MRASTI - x)^2)
where x takes values from the previous interval. How can i do it in R?
Thank you
I try this commands:
> for (i in 1:9998) {y<-1/length(MRASTI)*sum((MRASTI-x[i])^2)}
but this generates just a single value
Thank you
The problem is with
yin this line:At each loop iteration you are overwriting
y. The simple solution is:Without seeing some example objects and the code to create them and run your code, it is difficult to say if we could vectorise this for you so you don’t need a loop.