• Register
0 votes

Problem :

I have received below error message:

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


Error in while (condition) { : missing value where TRUE/FALSE needed

What does it actually mean, and how can I fix this error?

6 5 3
7,540 points

Please log in or register to answer this question.

2 Answers

0 votes

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.

9 7 4
38,600 points
0 votes


Consider  having this same issue when trying to view a data set we imported. we could also view individual elements but not the whole data set. we solved it by converting it to a data frame using


R has a wierd (and super annoying) way of handling NAs. if your output is empty then nchar(output) will return integer(0). You can get around this by adding another if statement with if(length(nchar(output)) > 0){...}

I did tests with the function with far less observations, but also generating 0 obs in "Unique in SetY" And I had no problem viewing those lists

May be you forgot to update the "Save workspace to .Rdata upon exit" to Never. After that change, you re-started R-studio and the error message did not re-appear. 

Updating R and sp to the released versions will resolve this.

It was caused by a change in R's behavior on what nchar(NA) returns: see the help file of ?nchar, argument keepNA.

we think the issue might be your use of things like all$age7. we suspect that 'all' is the name of a data frame and you intend the mxMatrix named 'Age' to be a matrix full of definition variables.

Following code:

# definition variable
    labels=paste("data.age", c(7, 8, 1:6), sep=""),


10 6 4
31,120 points

Related questions

1 vote
1 answer 189 views
Problem: I have some knowledge about R and Rstudio. Currently I am trying to install the package known as dplyr but it constantly shows me the below error: Error in install.packages : missing value where TRUE/FALSE needed. Please find below my console history for your ... very limited knowledge about R and Rstudio so I am unable to fix it. I am still facing the same error please guide me.
asked May 26, 2020 Martin K 6.6k points
1 vote
1 answer 29 views
Problem: Let me put it as sim as I can. I have an if statement in my code and it returns a value. Since IF is a boolean statement it should return value whether it’s true or false. So, in my program when a method tests an argument and returns a true or ... as a parameter in a different method inside an IF statement. How should I do that? Any kind of help is appreciated by my side. Thanks.
asked Mar 17, 2020 Gavin 15.3k points
0 votes
1 answer 15 views
Problem: Hello programmers! I am learning to program, and I just got a little confused about boolean values and logical operators. I tried to run the following program: #include<iostream> using namespace std; int main() { bool check = false && true || true; ... program, I got the following output: Condition evaluated to true I am so confused about how this condition evaluates to true. Any help?
asked Dec 18, 2020 Code Learner 5.5k points
1 vote
2 answers 1.7K views
Problem : Currently I am learning Javascript. I know the expression false && anything is short-circuit evaluated to false. According to this information I can certainly expect false && true || true must be evaluate to the false. But this is not the case. I saw ... me in finding correct solution of below question. &ldquo;What is the value of the following expression? true || true && false&rdquo;?
asked Apr 6, 2020 morrisBson 3.2k points
0 votes
2 answers 58 views
Problems: I am new to programming, I need help, can anyone help me? Declare a variable isACustomer suitable for representing a true or false value?
asked Feb 14, 2020 maddi86 5.4k points
0 votes
1 answer 13 views
Problem: Hi! I am a beginner and while attempting an exam of Java, I came across a multiple choice question which was as follows: In a project, 2 classes must contain main method (True/False) I chose False because as far as I know, if two or more classes have main ... . I want to know the correct answer with proper reason. If any of you can tell me the correct answer, I would be grateful. Thanks
asked Nov 29, 2020 Code Learner 5.5k points
0 votes
1 answer 116 views
Problem : I am trying to learn the Selenium by myself. But now my Sendkeys is not working. Can anybody please help me to fix my issue. My code is as below: WebElement uname = driver.findElement(By.xpath("//*[@id='username']"));      uname.sendKeys("123456"); Below is the error: Exception in ... ip: '', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_161'
asked Feb 14, 2020 mphil 2.3k points
1 vote
1 answer 19 views
Problem: I am new in python programming an I have been learning for this some days. As a newbee I am still learning and and I am cofused about some things. My question is &ldquo;In an if/else statement, if the boolean expression is always false?&rdquo;
asked Apr 3, 2020 LizzyM 6.1k points
0 votes
1 answer 14 views
Problem: SAS transfers data to SCSI disks via parallel cables. True or False? a. True b. false
asked Jul 23, 2020 HenryL 620 points
1 vote
1 answer 1.2K views
Problem : Can someone please tell me what is wrong with my code? I have tried almost everything and still unable to understand why my code keeps giving me below error: Parse error on line 3: ...", "shortName": &ldquo;Simple&rdquo;, "longN -------------------------------------- ... 1, "versionLabel": 1.7 , "watchapp": { "watchface": true }, "appKeys": { "dummy": 0 }, "resources": { "media": [] } }
asked Jan 2, 2020 alecxe 7.5k points