**Solution :**

** **

Here the evaluation of the condition must have resulted in an NA. Any if condition must return either a TRUE or FALSE result as shown below :

if (NA) {}

## Error in if (NA) { : missing value where TRUE/FALSE needed

This can happen with anybody accidentally as the results of the calculations as shown below :

if(TRUE && sqrt(-1)) {}

## Error in if (TRUE && sqrt(-1)) { : missing value where TRUE/FALSE needed

** **

Also** **to test whether any object is missing please use is.na(x) rather than the x == NA.

I also ran into this error in the recent past when I was trying to check on the null or empty string as shown below :

if (x == NULL || x == '') {

Then I did the lot of research on it and at the end of it I realized my mistake and I changed it as below:

if (is.null(x) || x == '') {

** **

Hope it solves your issue.