Home > database >  Length Zero in r
Length Zero in r

Time:08-19

Greetings I am getting an error of

Error in if (nrow(pair) == 0) { :argument is of length zero

I have checked the other answers but do not seem to work on a variable like mine. Please check code below, please assist if you can.

pair<-NULL
if(exists("p.doa.ym")) pair <- rbind(pair, p.doa.ym[,1:2])
if(exists("p.doa.yd")) pair <- rbind(pair, p.doa.yd[,1:2]) 

if(nrow(pair) == 0) {
  print("THERE ARE NO MATCHES FOR TODAY. STOP HERE")
  quit()
}

CodePudding user response:

Since you set pair=NULL and then it might happen that pair stays null if those two if statements are not true, you either need to check if pair is null first, or you could set pair to an empty data frame, or something else.

One option:

if (!is.null(pair)) {
  if (nrow(pair)==0) {
    # your code
  }
}

Another option:

pair=data.frame()
# your code
  •  Tags:  
  • r
  • Related