I am looping through a matrix cell by cell and I want to change all of the values less than 1 to their negative reciprocal. Here is the loop I currently have
x <- 1:rowlength
y <- 1:colLength
for (i in x) {
for (j in y) {
Cell <- Nmatrix[i,j]
if (Cell<=1) {Cell = -1/Cell}
}
}
I keep getting the following error when i try to run the code:
Error in if (Cell <= 1) { : missing value where TRUE/FALSE needed
I am not sure what I am doing wrong. Any help is much appreciated.
Thanks
Nmatrix[Nmatrix < 1] <- -1/Nmatrix