[R] missing values error in if statement
Avi Gross
@v|gro@@ @end|ng |rom ver|zon@net
Fri May 20 00:50:46 CEST 2022
We are needing more info to reproduce and debug this problem of comparing an object you call "fraction" to the number 1.
It can only be reproduced if the value/type is known and seen to be compatible with a numeric or logical value.
Those work fine for me. Using a vector of length greater than 1 returns a different error than the one specified.
Why not tell us what typeof(fraction) and class(fraction) return or show how it was made?
One GUESS is that you created or are using a data type using some package. If so, it will not comparable to an integer or floating point unless the package made implicit or explicit ways to do the comparison. One obvious way is to use whatever you need to convert the fraction back to numeric before a comparison, or, if it supports it, change the "1" to a fraction and use whatever comparison method you have available that can compare two fractions.
-----Original Message-----
From: Jeff Newmiller <jdnewmil using dcn.davis.ca.us>
To: r-help using r-project.org; Neha gupta <neha.bologna90 using gmail.com>; r-help mailing list <r-help using r-project.org>
Sent: Thu, May 19, 2022 6:20 pm
Subject: Re: [R] missing values error in if statement
Not reproducible. Posted HTML.
On May 19, 2022 2:30:58 PM PDT, Neha gupta <neha.bologna90 using gmail.com> wrote:
>Why do I get the following error when my variable in the 'if statement' has
>no missing values.
>
>I check with is.na(my variable) and it has no missing values
>
>Error in if (fraction <= 1) { : missing value where TRUE/FALSE needed
>
>Best regards
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
--
Sent from my phone. Please excuse my brevity.
______________________________________________
R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
More information about the R-help
mailing list