Re: [R] [FORGED] Logical Operators' inconsistent Behavior

2017-05-22 Thread William Michels via R-help
Evaluation of the NOT, AND, OR logical statements below in MySQL
5.5.30-log Community Server (GPL) replicate R's truth tables for NOT,
AND, OR. See MySQL queries (below), which are in agreement with R
truth table code posted in this thread:


bash-3.2$ mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 346
Server version: 5.5.30-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SELECT FALSE, NULL, TRUE;
+---+--+--+
| FALSE | NULL | TRUE |
+---+--+--+
| 0 | NULL |1 |
+---+--+--+
1 row in set (0.00 sec)

mysql> SELECT NOT FALSE, NOT NULL, NOT TRUE;
+---+--+--+
| NOT FALSE | NOT NULL | NOT TRUE |
+---+--+--+
| 1 | NULL |0 |
+---+--+--+
1 row in set (0.00 sec)

mysql> SELECT FALSE AND FALSE,
-> FALSE AND NULL,
-> FALSE AND TRUE;
+-+++
| FALSE AND FALSE | FALSE AND NULL | FALSE AND TRUE |
+-+++
|   0 |  0 |  0 |
+-+++
1 row in set (0.00 sec)

mysql> SELECT NULL AND NULL,
-> NULL AND TRUE,
-> TRUE AND TRUE;
+---+---+---+
| NULL AND NULL | NULL AND TRUE | TRUE AND TRUE |
+---+---+---+
|  NULL |  NULL | 1 |
+---+---+---+
1 row in set (0.00 sec)

mysql> SELECT TRUE OR TRUE,
-> NULL OR TRUE,
-> FALSE OR TRUE;
+--+--+---+
| TRUE OR TRUE | NULL OR TRUE | FALSE OR TRUE |
+--+--+---+
|1 |1 | 1 |
+--+--+---+
1 row in set (0.00 sec)

mysql> SELECT NULL OR NULL,
-> FALSE OR NULL,
-> FALSE OR FALSE;
+--+---++
| NULL OR NULL | FALSE OR NULL | FALSE OR FALSE |
+--+---++
| NULL |  NULL |  0 |
+--+---++
1 row in set (0.00 sec)

mysql>


HTH,

Bill

William Michels, Ph.D.


On Sun, May 21, 2017 at 7:00 AM, Hadley Wickham  wrote:
> On Fri, May 19, 2017 at 6:38 AM, S Ellison  wrote:
>>> TRUE & FALSE is FALSE but TRUE & TRUE is TRUE, so TRUE & NA could be
>>> either TRUE or FALSE and consequently is NA.
>>>
>>> OTOH FALSE & (anything) is FALSE so FALSE & NA is FALSE.
>>>
>>> As I said *think* about it; don't just go with your immediate knee-jerk
>>> (simplistic) reaction.
>>
>> Hmm... not sure that was quite fair to the OP. Yes,  FALSE &  == 
>> FALSE. But 'NA' does not mean 'anything'; it means 'missing' (see ?'NA'). It 
>> is much less obvious that FALSE &  should generate a non-missing 
>> value. SQL, for example, generally  takes the view that any expression 
>> involving 'missing' is 'missing'.
>
> That's not TRUE ;)
>
> sqlite> select (3 > 2) OR NULL;
> 1
>
> sqlite> select (4 < 3) AND NULL;
> 0
>
> Hadley
>
>
> --
> http://hadley.nz
>
> __
> R-help@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.

__
R-help@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.


Re: [R] [FORGED] Logical Operators' inconsistent Behavior

2017-05-21 Thread William Michels via R-help
Looking below and online, R's truth tables for NOT, AND, OR are
identical to the NOT, AND, OR truth tables originating from Stephen
Cole Kleene's "strong logic of indeterminacy", as demonstrated on the
Wikipedia page entitled, "Three-Valued Logic"--specifically in the
section entitled "Kleene and Priest Logics":

https://en.wikipedia.org/wiki/Three-valued_logic#Kleene_and_Priest_logics

>
> ttNOT <- cbind(c(FALSE, NA, TRUE), !c(FALSE, NA, TRUE))
> rownames(ttNOT) <- c("False", "na", "True")
> colnames(ttNOT) <- c("A", "Not(A)")
> ttNOT
  A Not(A)
False FALSE   TRUE
na   NA NA
True   TRUE  FALSE
>
> ttAND <- outer(c(FALSE, NA, TRUE), c(FALSE, NA, TRUE), "&" )
> rownames(ttAND) <- c("False", "na", "True")
> colnames(ttAND) <- c("False", "na", "True")
> ttAND
  Falsena  True
False FALSE FALSE FALSE
naFALSENANA
True  FALSENA  TRUE
>
> ttOR <- outer(c(FALSE, NA, TRUE), c(FALSE, NA, TRUE), "|" )
> rownames(ttOR) <- c("False", "na", "True")
> colnames(ttOR) <- c("False", "na", "True")
> ttOR
  False   na True
False FALSE   NA TRUE
na   NA   NA TRUE
True   TRUE TRUE TRUE
>
>

The bottom section of the same Wikipedia page (section entitled
"Application in SQL" ), and an additional Wikipedia page entitled
"Null (SQL)" discusses how the Kleene logic described above is
differentially implemented in SQL.

https://en.wikipedia.org/wiki/Null_(SQL)

HTH,

Bill

William Michels, Ph.D.




On Sun, May 21, 2017 at 7:00 AM, Hadley Wickham  wrote:
> On Fri, May 19, 2017 at 6:38 AM, S Ellison  wrote:
>>> TRUE & FALSE is FALSE but TRUE & TRUE is TRUE, so TRUE & NA could be
>>> either TRUE or FALSE and consequently is NA.
>>>
>>> OTOH FALSE & (anything) is FALSE so FALSE & NA is FALSE.
>>>
>>> As I said *think* about it; don't just go with your immediate knee-jerk
>>> (simplistic) reaction.
>>
>> Hmm... not sure that was quite fair to the OP. Yes,  FALSE &  == 
>> FALSE. But 'NA' does not mean 'anything'; it means 'missing' (see ?'NA'). It 
>> is much less obvious that FALSE &  should generate a non-missing 
>> value. SQL, for example, generally  takes the view that any expression 
>> involving 'missing' is 'missing'.
>
> That's not TRUE ;)
>
> sqlite> select (3 > 2) OR NULL;
> 1
>
> sqlite> select (4 < 3) AND NULL;
> 0
>
> Hadley
>
>
> --
> http://hadley.nz
>
> __
> R-help@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.

__
R-help@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.


Re: [R] [FORGED] Logical Operators' inconsistent Behavior

2017-05-21 Thread Hadley Wickham
On Fri, May 19, 2017 at 6:38 AM, S Ellison  wrote:
>> TRUE & FALSE is FALSE but TRUE & TRUE is TRUE, so TRUE & NA could be
>> either TRUE or FALSE and consequently is NA.
>>
>> OTOH FALSE & (anything) is FALSE so FALSE & NA is FALSE.
>>
>> As I said *think* about it; don't just go with your immediate knee-jerk
>> (simplistic) reaction.
>
> Hmm... not sure that was quite fair to the OP. Yes,  FALSE &  == 
> FALSE. But 'NA' does not mean 'anything'; it means 'missing' (see ?'NA'). It 
> is much less obvious that FALSE &  should generate a non-missing 
> value. SQL, for example, generally  takes the view that any expression 
> involving 'missing' is 'missing'.

That's not TRUE ;)

sqlite> select (3 > 2) OR NULL;
1

sqlite> select (4 < 3) AND NULL;
0

Hadley


-- 
http://hadley.nz

__
R-help@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.


Re: [R] [FORGED] Logical Operators' inconsistent Behavior

2017-05-20 Thread Duncan Murdoch

On 20/05/2017 5:53 AM, Martin Maechler wrote:

Ramnik Bansal 
on Sat, 20 May 2017 08:52:55 +0530 writes:


> Taking this question further.
> If I use a complex number or a numeric as an operand in logical
> operations, to me it APPEARS that these two types are first coerced to
> LOGICAL internally and then THIS logical output is further used as the
> operand.

> For eg.
>> x <- 4+5i; c(x & F, x & T, x | F, x | T)
> [1] FALSE  TRUE  TRUE  TRUE

> This output is consistent with
>> x <- 4+5i; c(as.logical(x) & F, as.logical(x) & T, as.logical(x) | F, 
as.logical(x) | T)
> [1] FALSE  TRUE  TRUE  TRUE

> This consistency makes me draw an on-the-surface conclusion that in
> the case of logical operations if the operand is not of type 'logical'
> it is first coerced into 'logical'.

That conclusion is wrong as you show below.
Rather, as the error message says,
logical
"operations are possible only for numeric, logical or complex types"

Again:

1) Logical/Arithmetic  operations "work" with "numeric-like" types, namely
  numeric, logical or complex, (and numeric = {integer, double})

  ==> all other types give an error (the one you've cited twice)

2) For "numeric-like" types and *logical* operations (&, |, !; plus && and ||)
   the equivalent of as.logical() is applied before performing the Op.

Seems pretty consistent ...
and also according to the principle of "least surprise" (for me at least).



The surprise is that as.logical("TRUE") returns TRUE, whereas automatic 
coercion doesn't apply to character strings.  I don't think we should 
change this, but it is an inconsistency.  (We could perhaps mention it 
in the ?logical help page.)


Duncan Murdoch

Duncan Murdoch

__
R-help@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.


Re: [R] [FORGED] Logical Operators' inconsistent Behavior

2017-05-20 Thread Martin Maechler
> Ramnik Bansal 
> on Sat, 20 May 2017 08:52:55 +0530 writes:

> Taking this question further.
> If I use a complex number or a numeric as an operand in logical
> operations, to me it APPEARS that these two types are first coerced to
> LOGICAL internally and then THIS logical output is further used as the
> operand.

> For eg.
>> x <- 4+5i; c(x & F, x & T, x | F, x | T)
> [1] FALSE  TRUE  TRUE  TRUE

> This output is consistent with
>> x <- 4+5i; c(as.logical(x) & F, as.logical(x) & T, as.logical(x) | F, 
as.logical(x) | T)
> [1] FALSE  TRUE  TRUE  TRUE

> This consistency makes me draw an on-the-surface conclusion that in
> the case of logical operations if the operand is not of type 'logical'
> it is first coerced into 'logical'.

That conclusion is wrong as you show below.
Rather, as the error message says,
logical
"operations are possible only for numeric, logical or complex types"

Again:

1) Logical/Arithmetic  operations "work" with "numeric-like" types, namely
  numeric, logical or complex, (and numeric = {integer, double})

  ==> all other types give an error (the one you've cited twice)

2) For "numeric-like" types and *logical* operations (&, |, !; plus && and ||)
   the equivalent of as.logical() is applied before performing the Op.
   
Seems pretty consistent ...
and also according to the principle of "least surprise" (for me at least).

__
R-help@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.


Re: [R] [FORGED] Logical Operators' inconsistent Behavior

2017-05-19 Thread Ramnik Bansal
Taking this question further.

If I use a complex number or a numeric as an operand in logical
operations, to me it APPEARS that these two types are first coerced to
LOGICAL internally and then THIS logical output is further used as the
operand.

For eg.
> x <- 4+5i; c(x & F, x & T, x | F, x | T)
[1] FALSE  TRUE  TRUE  TRUE

This output is consistent with
> x <- 4+5i; c(as.logical(x) & F, as.logical(x) & T, as.logical(x) | F, 
> as.logical(x) | T)
[1] FALSE  TRUE  TRUE  TRUE

This consistency makes me draw an on-the-surface conclusion that in
the case of logical operations if the operand is not of type 'logical'
it is first coerced into 'logical'.

But this doesn't seem to be true because if that was the case it
should have worked with character operands as well, albeit following
the rules of NA in logical operations ( as per R help manual)

For e.g.
> x <- "abc"; c(as.logical(x) & F, as.logical(x) & T, as.logical(x) | F, 
> as.logical(x) | T)
[1] FALSENANA  TRUE

Whereas
> x <- "abc"; c(x & F, x & T, x | F, x | T)
Error in x & F :
  operations are possible only for numeric, logical or complex types

So my question basically is :
What does R actually do in the case of complex numbers Vs characters
as operands in logical operations ?

And adding some more:

consistent with above behavior with character,
> NA_character_ & FALSE
Error in NA_character_ & FALSE :
  operations are possible only for numeric, logical or complex types

R documentation on the other hand mentions:
Logical computations treat NA as a missing TRUE/FALSE value and so may
return TRUE or FALSE if the expression does not depend on the NA
operand.

Isn't NA mentioned in the R documentation to be interpreted as NA
irrespective of the type? Else, shouldn't the R documentation mention
"Logical computations treat NA except NA_character_ as a missing..."


Thanks,
Ramnik

ps: I hope I have phrased my question well enough this time not to end
up inviting the wrath of some R-Gods around on a mere R-mortal that I
am at this stage :) The more am becoming familiar with R, the more am
loving it and definitely don't intend to offend R Gods!

On Fri, May 19, 2017 at 6:57 PM, Ted Harding  wrote:
> [I unadvertently sent my reply below to Jeremie, instead of R-help.
> Also, I havve had an additional thought which may clarify things
> for R users].
> [Original reply]:
> The point about this is that (as Rolf wrote) FALSE & (anything)
> is FALSE, provided logical NA is either TRUE ot FALSE but,
> because the "NA" says that it is not known which it is,
> it could be "anything". And, indeed, if "NA" is given the
> "missing" meaning and if we assume that a missing logical value
> did indeed have a value (necessarily either TRUE or FALSE),
> then it follows logically that FALSE & NA = FALS£.
>
> On the other hand, if with the "missing" interpretation of "NA"
> we don't even know that it is a logical, then it might be fair
> enough to say FALSE & NA = NA.
> Ted.
>
> [Additional thought]:
> Testing to see what would happen if the NA were not loigical,
> I put myself (not being logical ... ) on the line, facing up to R:
>X <- "Ted"
>FALSE & X
>Error in FALSE & X :
>operations are possible only for numeric, logical or complex types
> So R will refuse to deal with any variable which cannot partake in
> a logical expression.
>
> Ted.
>
> On Fri, 2017-05-19 at 14:24 +0200, Jérémie Juste wrote:
>> My apologies if I was not clear enough,
>>
>> TRUE & NA could be either TRUE or FALSE and consequently is NA.
>> why is   FALSE & NA = FALSE?  NA could be TRUE or FALSE, so FALSE & NA
>> should be NA?
>>
>>
>> On Fri, May 19, 2017 at 2:13 PM, Rolf Turner 
>> wrote:
>>
>> > On 20/05/17 00:01, Jérémie Juste wrote:
>> >
>> >> Hello,
>> >>
>> >> Rolf said,
>> >>
>> >> TRUE & FALSE is FALSE but TRUE & TRUE is TRUE, so TRUE & NA could be
>> >> either TRUE or FALSE and consequently is NA.
>> >>
>> >> OTOH FALSE & (anything) is FALSE so FALSE & NA is FALSE.
>> >>
>> >>
>> >> According to this logic why is
>> >>
>> >> FALSE & NA
>> >>
>> >> [1] FALSE
>> >>
>> >
>> > Huh
>> >
>> >
>> > cheers,
>> >
>> > Rolf Turner
>> >
>> > --
>> > Technical Editor ANZJS
>> > Department of Statistics
>> > University of Auckland
>> > Phone: +64-9-373-7599 ext. 88276
>> >
>>
>>
>>
>> --
>> Jérémie Juste
>>
>>   [[alternative HTML version deleted]]
>>
>> __
>> R-help@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.
>
> __
> R-help@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 

Re: [R] [FORGED] Logical Operators' inconsistent Behavior

2017-05-19 Thread Ted Harding
[I unadvertently sent my reply below to Jeremie, instead of R-help.
Also, I havve had an additional thought which may clarify things
for R users].
[Original reply]:
The point about this is that (as Rolf wrote) FALSE & (anything)
is FALSE, provided logical NA is either TRUE ot FALSE but,
because the "NA" says that it is not known which it is,
it could be "anything". And, indeed, if "NA" is given the
"missing" meaning and if we assume that a missing logical value
did indeed have a value (necessarily either TRUE or FALSE),
then it follows logically that FALSE & NA = FALS£.

On the other hand, if with the "missing" interpretation of "NA"
we don't even know that it is a logical, then it might be fair
enough to say FALSE & NA = NA.
Ted.

[Additional thought]:
Testing to see what would happen if the NA were not loigical,
I put myself (not being logical ... ) on the line, facing up to R:
   X <- "Ted"
   FALSE & X
   Error in FALSE & X : 
   operations are possible only for numeric, logical or complex types
So R will refuse to deal with any variable which cannot partake in
a logical expression.

Ted.

On Fri, 2017-05-19 at 14:24 +0200, Jérémie Juste wrote:
> My apologies if I was not clear enough,
> 
> TRUE & NA could be either TRUE or FALSE and consequently is NA.
> why is   FALSE & NA = FALSE?  NA could be TRUE or FALSE, so FALSE & NA
> should be NA?
> 
> 
> On Fri, May 19, 2017 at 2:13 PM, Rolf Turner 
> wrote:
> 
> > On 20/05/17 00:01, Jérémie Juste wrote:
> >
> >> Hello,
> >>
> >> Rolf said,
> >>
> >> TRUE & FALSE is FALSE but TRUE & TRUE is TRUE, so TRUE & NA could be
> >> either TRUE or FALSE and consequently is NA.
> >>
> >> OTOH FALSE & (anything) is FALSE so FALSE & NA is FALSE.
> >>
> >>
> >> According to this logic why is
> >>
> >> FALSE & NA
> >>
> >> [1] FALSE
> >>
> >
> > Huh
> >
> >
> > cheers,
> >
> > Rolf Turner
> >
> > --
> > Technical Editor ANZJS
> > Department of Statistics
> > University of Auckland
> > Phone: +64-9-373-7599 ext. 88276
> >
> 
> 
> 
> -- 
> Jérémie Juste
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@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.

__
R-help@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.

Re: [R] [FORGED] Logical Operators' inconsistent Behavior

2017-05-19 Thread Jeff Newmiller
FALSE & FALSE -> FALSE
FALSE & TRUE -> FALSE

Why do you need to know what the second value is? It doesn't matter what it 
is... the answer is FALSE. 
-- 
Sent from my phone. Please excuse my brevity.

On May 19, 2017 5:24:06 AM PDT, "Jérémie Juste"  wrote:
>My apologies if I was not clear enough,
>
>TRUE & NA could be either TRUE or FALSE and consequently is NA.
>why is   FALSE & NA = FALSE?  NA could be TRUE or FALSE, so FALSE & NA
>should be NA?
>
>
>On Fri, May 19, 2017 at 2:13 PM, Rolf Turner 
>wrote:
>
>> On 20/05/17 00:01, Jérémie Juste wrote:
>>
>>> Hello,
>>>
>>> Rolf said,
>>>
>>> TRUE & FALSE is FALSE but TRUE & TRUE is TRUE, so TRUE & NA could be
>>> either TRUE or FALSE and consequently is NA.
>>>
>>> OTOH FALSE & (anything) is FALSE so FALSE & NA is FALSE.
>>>
>>>
>>> According to this logic why is
>>>
>>> FALSE & NA
>>>
>>> [1] FALSE
>>>
>>
>> Huh
>>
>>
>> cheers,
>>
>> Rolf Turner
>>
>> --
>> Technical Editor ANZJS
>> Department of Statistics
>> University of Auckland
>> Phone: +64-9-373-7599 ext. 88276
>>
>
>
>
>-- 
>Jérémie Juste
>
>   [[alternative HTML version deleted]]
>
>__
>R-help@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.

__
R-help@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.

Re: [R] [FORGED] Logical Operators' inconsistent Behavior

2017-05-19 Thread Duncan Murdoch

On 19/05/2017 8:48 AM, S Ellison wrote:

SQL, for example, generally takes the view that any
expression involving 'missing' is 'missing'.


Well, then SQL gets it wrong.


Well, that's a view. But paraphrasing an  R Turner from a few lines away in the 
same email:


One should be very, very circumspect about presuming to know better than
SQL


It's a choice. I understand and respect R's. But I can also understand why 
someone might have expected something different.


You're right about SQL.  But for R, it's pretty simple to read the help 
page on NA, and it is quite explicit about this:


"Logical computations treat NA as a missing TRUE/FALSE value, and so may 
return TRUE or FALSE if the expression does not depend on the NA operand."


I'm surprised nobody on this thread has quoted that before.

Duncan Murdoch

__
R-help@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.


Re: [R] [FORGED] Logical Operators' inconsistent Behavior

2017-05-19 Thread peter dalgaard

> On 19 May 2017, at 14:24 , Jérémie Juste  wrote:
> 
> My apologies if I was not clear enough,
> 
> TRUE & NA could be either TRUE or FALSE and consequently is NA.
> why is   FALSE & NA = FALSE?  NA could be TRUE or FALSE, so FALSE & NA
> should be NA?
> 

At the risk of flogging a dead horse:

FALSE & TRUE = FALSE
FALSE & FALSE = FALSE

FALSE & x = FALSE, whatever the value of x, hence 

FALSE & NA = FALSE

Get it?  

-pd


> 
> On Fri, May 19, 2017 at 2:13 PM, Rolf Turner 
> wrote:
> 
>> On 20/05/17 00:01, Jérémie Juste wrote:
>> 
>>> Hello,
>>> 
>>> Rolf said,
>>> 
>>> TRUE & FALSE is FALSE but TRUE & TRUE is TRUE, so TRUE & NA could be
>>> either TRUE or FALSE and consequently is NA.
>>> 
>>> OTOH FALSE & (anything) is FALSE so FALSE & NA is FALSE.
>>> 
>>> 
>>> According to this logic why is
>>> 
>>>FALSE & NA
>>> 
>>> [1] FALSE
>>> 
>> 
>> Huh
>> 
>> 
>> cheers,
>> 
>> Rolf Turner
>> 
>> --
>> Technical Editor ANZJS
>> Department of Statistics
>> University of Auckland
>> Phone: +64-9-373-7599 ext. 88276
>> 
> 
> 
> 
> -- 
> Jérémie Juste
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
R-help@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.

Re: [R] [FORGED] Logical Operators' inconsistent Behavior

2017-05-19 Thread S Ellison
> > SQL, for example, generally takes the view that any 
> > expression involving 'missing' is 'missing'.
> 
> Well, then SQL gets it wrong.

Well, that's a view. But paraphrasing an  R Turner from a few lines away in the 
same email:

> One should be very, very circumspect about presuming to know better than
> SQL

It's a choice. I understand and respect R's. But I can also understand why 
someone might have expected something different.

S


***
This email and any attachments are confidential. Any use...{{dropped:8}}

__
R-help@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.


Re: [R] [FORGED] Logical Operators' inconsistent Behavior

2017-05-19 Thread Jérémie Juste
My apologies if I was not clear enough,

TRUE & NA could be either TRUE or FALSE and consequently is NA.
why is   FALSE & NA = FALSE?  NA could be TRUE or FALSE, so FALSE & NA
should be NA?


On Fri, May 19, 2017 at 2:13 PM, Rolf Turner 
wrote:

> On 20/05/17 00:01, Jérémie Juste wrote:
>
>> Hello,
>>
>> Rolf said,
>>
>> TRUE & FALSE is FALSE but TRUE & TRUE is TRUE, so TRUE & NA could be
>> either TRUE or FALSE and consequently is NA.
>>
>> OTOH FALSE & (anything) is FALSE so FALSE & NA is FALSE.
>>
>>
>> According to this logic why is
>>
>> FALSE & NA
>>
>> [1] FALSE
>>
>
> Huh
>
>
> cheers,
>
> Rolf Turner
>
> --
> Technical Editor ANZJS
> Department of Statistics
> University of Auckland
> Phone: +64-9-373-7599 ext. 88276
>



-- 
Jérémie Juste

[[alternative HTML version deleted]]

__
R-help@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.

Re: [R] [FORGED] Logical Operators' inconsistent Behavior

2017-05-19 Thread Rolf Turner

On 20/05/17 00:01, Jérémie Juste wrote:

Hello,

Rolf said,

TRUE & FALSE is FALSE but TRUE & TRUE is TRUE, so TRUE & NA could be
either TRUE or FALSE and consequently is NA.

OTOH FALSE & (anything) is FALSE so FALSE & NA is FALSE.


According to this logic why is

FALSE & NA

[1] FALSE


Huh

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
R-help@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.

Re: [R] [FORGED] Logical Operators' inconsistent Behavior

2017-05-19 Thread Rolf Turner

On 19/05/17 23:38, S Ellison wrote:

TRUE & FALSE is FALSE but TRUE & TRUE is TRUE, so TRUE & NA could be
either TRUE or FALSE and consequently is NA.

OTOH FALSE & (anything) is FALSE so FALSE & NA is FALSE.

As I said *think* about it; don't just go with your immediate knee-jerk
(simplistic) reaction.


Hmm... not sure that was quite fair to the OP.


The OP complained that the logical operators in R are inconsistent. 
This is an arrogant and presumptuous assertion that deserves a 
reprimand.  One should be very, very circumspect about presuming to know 
better than R.



Yes, FALSE &
== FALSE. But 'NA' does not mean 'anything'; it means 'missing' (see
?'NA').


Well, duh.  Yes, I know what NA means.  If it's missing, you don't know 
what it's value is.  But it doesn't *matter* what its value is; FALSE &

 is FALSE.  So FALSE & NA is FALSE, irrespective of what NA
"really" is.


It is much less obvious that FALSE &  should generate a
non-missing value. SQL, for example, generally takes the view that any
expression involving 'missing' is 'missing'.


Well, then SQL gets it wrong.


And R's behaviour can look odd if the vagaries of real data intervene:
b1 <- c(A=TRUE, C=FALSE)
b2 <- c(A=FALSE, B=FALSE, C=TRUE)
b1['B'] & b2['B']
#Which returns
# 
# FALSE

which - particularly since it appears without warning 


Everything appears without warning.  Nobody expected the Spanish 
Inquisition.



 - is not an obviously sensible outcome.


Why not?  It's obviously sensible to me, and to anyone else who is 
thinking.  Since b1['B'] is NA (b1 doesn't have an entry named 'B') and 
b2['B'] is FALSE we get NA & FALSE which is FALSE.  Where's the problem?


The "" in the output that you show is the *name* of the 'B' entry of 
b1, and since there isn't one, it doesn't have a name.  So the name is 
missing whence it is rendered as "" (missing character).



I am not suggesting a change to R's logical operations, which have
clearly been thought through (that is evident from NA ==
FALSE == FALSE). But R's behaviour looks to me like a choice among
difficult alternatives, rather than the only possible choice. I'd
give the OP some credit for that.


You seem to be arguing for the sake of arguing.  It's really quite 
straightforward *if* you *think* about it.


cheers,

Rolf

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
R-help@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.


Re: [R] [FORGED] Logical Operators' inconsistent Behavior

2017-05-19 Thread Jérémie Juste
Hello,

Rolf said,

TRUE & FALSE is FALSE but TRUE & TRUE is TRUE, so TRUE & NA could be
either TRUE or FALSE and consequently is NA.

OTOH FALSE & (anything) is FALSE so FALSE & NA is FALSE.


According to this logic why is

> FALSE & NA
>
[1] FALSE
?

Best regards,

Jeremie

On Fri, May 19, 2017 at 1:38 PM, S Ellison  wrote:

> > TRUE & FALSE is FALSE but TRUE & TRUE is TRUE, so TRUE & NA could be
> > either TRUE or FALSE and consequently is NA.
> >
> > OTOH FALSE & (anything) is FALSE so FALSE & NA is FALSE.
> >
> > As I said *think* about it; don't just go with your immediate knee-jerk
> > (simplistic) reaction.
>
> Hmm... not sure that was quite fair to the OP. Yes,  FALSE &  ==
> FALSE. But 'NA' does not mean 'anything'; it means 'missing' (see ?'NA').
> It is much less obvious that FALSE &  should generate a
> non-missing value. SQL, for example, generally  takes the view that any
> expression involving 'missing' is 'missing'.
>
> And R's behaviour can look odd if the vagaries of real data intervene:
> b1 <- c(A=TRUE, C=FALSE)
> b2 <- c(A=FALSE, B=FALSE, C=TRUE)
> b1['B'] & b2['B']
> #Which returns
> # 
> # FALSE
>
> which - particularly since it appears without warning - is not an
> obviously sensible outcome.
>
> I am not suggesting a change to R's logical operations, which have clearly
> been thought through (that is evident from NA == FALSE == FALSE).
> But R's behaviour looks to me like a choice among difficult alternatives,
> rather than the only possible choice. I'd give the OP some credit for that.
>
> S Ellison
>
>
> S Ellison
>
>
>
>
>
>
>
> ***
> This email and any attachments are confidential. Any u...{{dropped:18}}

__
R-help@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.


Re: [R] [FORGED] Logical Operators' inconsistent Behavior

2017-05-19 Thread S Ellison
> TRUE & FALSE is FALSE but TRUE & TRUE is TRUE, so TRUE & NA could be
> either TRUE or FALSE and consequently is NA.
> 
> OTOH FALSE & (anything) is FALSE so FALSE & NA is FALSE.
>
> As I said *think* about it; don't just go with your immediate knee-jerk
> (simplistic) reaction.

Hmm... not sure that was quite fair to the OP. Yes,  FALSE &  == 
FALSE. But 'NA' does not mean 'anything'; it means 'missing' (see ?'NA'). It is 
much less obvious that FALSE &  should generate a non-missing value. 
SQL, for example, generally  takes the view that any expression involving 
'missing' is 'missing'. 

And R's behaviour can look odd if the vagaries of real data intervene:
b1 <- c(A=TRUE, C=FALSE)
b2 <- c(A=FALSE, B=FALSE, C=TRUE)
b1['B'] & b2['B']
#Which returns
#  
# FALSE 

which - particularly since it appears without warning - is not an obviously 
sensible outcome. 

I am not suggesting a change to R's logical operations, which have clearly been 
thought through (that is evident from NA == FALSE == FALSE). But R's 
behaviour looks to me like a choice among difficult alternatives, rather than 
the only possible choice. I'd give the OP some credit for that.

S Ellison


S Ellison







***
This email and any attachments are confidential. Any use...{{dropped:8}}

__
R-help@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.


Re: [R] [FORGED] Logical Operators' inconsistent Behavior

2017-05-19 Thread Rolf Turner


On 19/05/17 21:48, Ramnik Bansal wrote:


Hi,

I need to understand the inconsistent behaviour of & and I operators when
used with NA.

The code below explains this inconsistency


TRUE & NA

[1] NA


FALSE & NA

[1] FALSE


TRUE & NA

[1] NA


FALSE | NA

[1] NA


TRUE | NA

[1] TRUE


TRUE == NA

[1] NA


FALSE == NA

[1] NA


What inconsistency?  It all makes complete sense.  Think about it.

TRUE & FALSE is FALSE but TRUE & TRUE is TRUE, so TRUE & NA could be
either TRUE or FALSE and consequently is NA.

OTOH FALSE & (anything) is FALSE so FALSE & NA is FALSE.

Und so weiter.

As I said *think* about it; don't just go with your immediate knee-jerk 
(simplistic) reaction.


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
R-help@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.