Selamola Tloubatla
Selamola Tloubatla

Reputation: 38

Length Zero in r

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()
}

Upvotes: 1

Views: 236

Answers (1)

user2974951
user2974951

Reputation: 10375

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

Upvotes: 1

Related Questions