I have two matrices (x and y) - reproduced using below code.
x <- structure(c(0.11, 0.91, 1.28, 0.32, 0.23, 0.45, 1.17, 0.68, 0.85,
0.46), .Dim = c(10L, 1L))
y <- structure(c(3, 5, 7, 9, 11, 13, 18, 20, 22, 26), .Dim = c(10L,
1L))
What I am trying to do is use the following For and if/else combination. What I am trying to do is IF value in x is <0.3, a new matrix column is created in y [i,2] that states either 0 (False, value in x isn't less than 0.3) or 1 (True, value in x is greater than 0.3)
I keep getting the error code "Error in y[i, 2] : subscript out of bounds"
for (i in 1:10){
if (x[i,1]<0.3){
y[i,2] == 0
} else {
y[i,2] == 1
}
}
Please don't suggest alternative ways (i.e., not using for/if/else) because this is the way that I have been told is required for this project.