I want to recode the values in the matrix so that all the values are <=. 2 became 2, <=. 4 became 3, etc. However, there are gaps in my data that I do not want to change (keep them NA). Here you will find a simplified version of my code. Using na.omit works great for first changes
try <- matrix(c(0.78,0.62,0.29,0.47,0.30,0.63,0.30,0.20,0.15,0.58,0.52,0.64,
0.76,0.32,0.64,0.50,0.67,0.27, NA), nrow = 19)
try[na.omit(try <= .2)] <- 2
However, when I do the same for a higher category, NA also changes:
try[na.omit(try <= .8)] <- 5
Can someone explain to me what the difference is between the two, and why the second also changes the value of NA, and the first does not? Or am I doing something else wrong?
source
share