Bloomberg Cycle Code: missing value where TRUE/FALSE needed

I have written some code whereby I am looking to remove stocks within my universe if they are below a certain mktcap. I have written the code below but it seems to give an error in certain circumstances. I am assuming it is to do with the construction of my if else formula. The error that I am getting is:

"missing value where TRUE/FALSE needed"

I would really appreciate your advice. Thank you in advance.

  for (i in 1:nrow(t)){
    qq <- bdh(t[i,], 
              fields = c("CUR_MKT_CAP"), 
     = aa, = a)
    qq$date <- as.Date(qq$date, format = "%d/%m/%Y")
    qq$CUR_MKT_CAP <- as.numeric(qq$CUR_MKT_CAP)
    qqlength <- (last(qq$CUR_MKT_CAP))/1000
    #  print(qqlength)

    if(qqlength >= mktcap){
      mktcapfilter[i] <-  t[i,]}else{
        mktcapfilter[i] <- 0