Q:

R: If i is true then assign string to matrix

I can't get a for loop to assign the string 'NA' when none of the other conditions are met.
This is what I've tried...
Height <- c(1.6,3.4,0.42,n/a, 0.5,n/a,1.5,0,n/a,22.0)
Height <- matrix(Height)  

h_cat <- matrix(, nrow = length(Height), ncol = 1)
for (i in 1:length(Height)){
  if (Height[i]==0)
    h_cat[i] <- 'NA'
  if (Height[i]>0 & Height[i]<2)
    print(Height[i])
    h_cat[i] <- '0-2 m'
    #print(h_cat[i])
  if (Height[i]>=2 & Height[i]<5)
    h_cat[i] <- '2-5 m'
  if (Height[i]>=5 & Height[i]<10)
    h_cat[i] <- '5-10 m'
  if (Height[i]>=10)
    h_cat[i] <- '>10 m'
  else
    h_cat[i] <- 'NA'
}

I had a go with is.na() but no luck either.
Update
Sorry that was rushed. Data added.

A:

There are two main problems with the current code.

First can be exemplified by NA == 0, which returns NA. Thus you can only use the if function on the non-NA entries: which(!is.na(Height)).
The logic of your if-else construction is not working as what seems to be the intention.

The below I believe achieves your intentions:
# Data needs to be numeric to check with ">"
Height[Height == "n/a", ] <- NA
Height <- as.numeric(Height)

h_cat <- matrix(, nrow = length(Height), ncol = 1)

# Can't have NA in logical tests
non_na_entries <- which(!is.na(Height))
for (i in non_na_entries) {
  if (Height[i] == 0) {
    h_cat[i] <- NA
  } else if (Height[i] > 0 & Height[i] < 2) {
    h_cat[i] <- '0-2 m'
  } else if (Height[i] >= 2 & Height[i] < 5) {
    h_cat[i] <- '2-5 m'
  } else if (Height[i] >= 5 & Height[i] < 10) {
    h_cat[i] <- '5-10 m'
  } else if (Height[i] >= 10) {
    h_cat[i] <- '>10 m'
  } else
    h_cat[i] <- NA
}

    h_cat

     [,1]   
 [1,] "0-2 m"
 [2,] "2-5 m"
 [3,] "0-2 m"
 [4,] NA     
 [5,] "0-2 m"
 [6,] NA     
 [7,] "0-2 m"
 [8,] NA     
 [9,] NA     
[10,] ">10 m"

