[R] result NA , but expected True or False

William Dunlap wdunlap at tibco.com
Mon Aug 10 18:26:47 CEST 2015


The || operator will always return a result of type 'logical' and length 1.
You gave it two operands of length 0, so it returned the logical value NA,
meaning it had no idea what the result should be.  If you give it operands
of length > 1, it will use the only the first elements of them.  (S and S+
considered length 0 operands to || and && an error and warned about
length>1 operands, but R makes no comment about either case).

Perhaps you want to use the | operator, which acts like == and +, returning
a result as long as the longer of its operands, unless one operand has zero
elements, in which case it returns a length 0 result.


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Sun, Aug 9, 2015 at 8:45 PM, Ragia Ibrahim <ragia11 at hotmail.com> wrote:

> Dear Group,
> Kindly,
>
> I have those two lines
> if(  (z_nebla==0) ||  (z_nebla_dash==0) )
>            CM <- 0         else
>
>                CM <-  0.5 *(1/a)  +   0.5*(1/b)
>
> when running it
>
> I got this
>
> z_nebla==0)
> logical(0)
> > (z_nebla_dash==0)
> logical(0)
> > (z_nebla==0) ||  (z_nebla_dash==0)
> [1] NA
>
>
> why  (z_nebla==0) ||  (z_nebla_dash==0)
> gives me NA ?
>
> thanks in advance
> Ragia
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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