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] Identyfing rows with specific conditions

2017-05-21 Thread Bert Gunter
More clarification:

Are your "tables" matrices or data frames? (If you don't know what
this means, you need to spend a little time with a e.g. web tutorial
to learn).

Also, does Meal A Meal B order count? -- i.e. is Meal A = 2, Meal B =
15 the same as Meal A = 15 and Meal B = 2?  This is important.

Cheers,

Bert

Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sun, May 21, 2017 at 5:10 PM, Allaisone 1  wrote:
>
> Hi All..,
>
> I have 2 tables. The first one contains 2 columns with the headers say "meal 
> A code" & "meal B code " in a table called "Meals" with 2000 rows each of 
> which with a different combination of meals(unique combination per row).
>
>
>>Meals
>
> meal A code  meal B code
>
> 1  34   66
>
> 2   89  39
>
> 3   25   77
>
> The second table(customers) shows customers ids in the first column with 
> Meals codes(M) next to each customer. There are about 300,000 customers 
> (300,000 rows).
>
>> Customers
>  1 2 3   4..30
>  id   M1  M2   M3
> 1   15  773425
> 2   11  2534 39
> 385 89 2577
> .
> .
> 300,000
>
> I would like to identify all customers ids who have had each meal combination 
> in the first table so the final output would be the first table with ids 
> attached next to each meal combination in each row like this:
>
>>IdsMeals
>
>
>   MAcode  MBcode  ids
>
> 1 343911
>
> 2 25   34  15   11
>
> 3  25 7715   85
>
> Would you please suggest any solutions to this problem?
>
> Regards
>
> [[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] Identyfing rows with specific conditions

2017-05-21 Thread Bert Gunter
Clarification:

Does each customer have the same number of meals or do they differ
from customer to customer? If the latter, how are missing meals
notated? Do they always occur at the (right) end or can they occur
anywhere in the row?

Presumably each customer ID can have many different meal code
combinations, right ?(since they can have 30 different meals with
potentially 30 choose 2 = 435 combinations apiece)

Please make sure you reply to the list, not just to me, as I may not
pursue this further but am just trying to clarify for anyone else who
may wish to help.


Cheers,
Bert

Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sun, May 21, 2017 at 5:10 PM, Allaisone 1  wrote:
>
> Hi All..,
>
> I have 2 tables. The first one contains 2 columns with the headers say "meal 
> A code" & "meal B code " in a table called "Meals" with 2000 rows each of 
> which with a different combination of meals(unique combination per row).
>
>
>>Meals
>
> meal A code  meal B code
>
> 1  34   66
>
> 2   89  39
>
> 3   25   77
>
> The second table(customers) shows customers ids in the first column with 
> Meals codes(M) next to each customer. There are about 300,000 customers 
> (300,000 rows).
>
>> Customers
>  1 2 3   4..30
>  id   M1  M2   M3
> 1   15  773425
> 2   11  2534 39
> 385 89 2577
> .
> .
> 300,000
>
> I would like to identify all customers ids who have had each meal combination 
> in the first table so the final output would be the first table with ids 
> attached next to each meal combination in each row like this:
>
>>IdsMeals
>
>
>   MAcode  MBcode  ids
>
> 1 343911
>
> 2 25   34  15   11
>
> 3  25 7715   85
>
> Would you please suggest any solutions to this problem?
>
> Regards
>
> [[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] How to extract text contexts after clustering.

2017-05-21 Thread Ismail SEZEN
1- PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
2- PLEASE, first _read_ help for kmeans (?kmeans) function before using 
function.

> On 22 May 2017, at 05:33, θ ”  wrote:
> 
> hi:
> I need to extract the text contexts of top 1 group after clustering.
> But I have no idea how to sort the cluster size then extract the contexts of 
> top 1 clusters.

There isn’t a _top_ cluster for kmeans algorithm. There are _only_ clusters!

> 
> here is my cluster code:
> 
>> file <- read.csv("SiC CMP.csv", header = TRUE)

We don’t know what is in file$Main.IPC.

>> cluster_k<-length(unique(file$Main.IPC))
>> cl <- kmeans(IPC_Dtm , cluster_k)

What is IPC_Dtm?

> 
> 
> I have tried use��
> 
>> sort(cl$size, decreasing=T)

if you read the documentation, you would know cl$size means the number of 
points in each cluster. So, why do you sort them?

> [1] 341 107 104  80  51  22  15  11  10   8   8   5   5   5   4   4   4   3   
> 3   2   2
> [22]   2   2   2   2   2   2   1   1   1   1   1   1   1   1   1   1   1   1  
>  1   1   1
> [43]   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1
> 
> But I have no idea how to extract the contexts of top 1 cluster.

If you read the _Value_ section of kmeans documentation, you will have an idea 
how to extract context by using cl$cluster.

> 
> 
> Eva
> 
>   [[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.

[R] How to extract text contexts after clustering.

2017-05-21 Thread θ ”
hi:
I need to extract the text contexts of top 1 group after clustering.
But I have no idea how to sort the cluster size then extract the contexts of 
top 1 clusters.

here is my cluster code:

> file <- read.csv("SiC CMP.csv", header = TRUE)
> cluster_k<-length(unique(file$Main.IPC))
> cl <- kmeans(IPC_Dtm , cluster_k)


I have tried use��

> sort(cl$size, decreasing=T)
 [1] 341 107 104  80  51  22  15  11  10   8   8   5   5   5   4   4   4   3   
3   2   2
[22]   2   2   2   2   2   2   1   1   1   1   1   1   1   1   1   1   1   1   
1   1   1
[43]   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1

But I have no idea how to extract the contexts of top 1 cluster.


Eva

[[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] Somewhat obscure bug in R 3.4.0 building from source

2017-05-21 Thread Bert Gunter
... and whether or not Rich's suggestion resolves your difficulties,
please google such issues in future; e.g.

"report bugs R"

brought up all sorts of info on R bug reporting.

-- Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sun, May 21, 2017 at 7:30 AM, Peter Carbonetto
 wrote:
> Hi,
>
> I uncovered a bug in installing R 3.4.0 from source in Linux, following the
> standard procedure (configure; make; make install). Is this an appropriate
> place to report this bug? If not, can you please direct me to the
> appropriate place?
>
> The error occurs only when I do "make clean" followed by "make" again; make
> works the first time.
>
> The error is a failure to build NEWS.pdf:
>
> Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet,  :
>   pdflatex is not available
> Calls:  -> texi2pdf -> texi2dvi
> Execution halted
> make[1]: *** [NEWS.pdf] Error 1
> make: [docs] Error 2 (ignored)
>
> and can be reproduced wit the following sequence:
>
> ./configure
> make
> make clean
> make
>
> This suggests to me that perhaps "make clean" is not working.
>
> I'm happy to provide more details so that you are able to reproduce the bug.
>
> Thanks,
>
> Peter Carbonetto, Ph.D.
> Computational Staff Scientist, Statistics & Genetics
> Research Computing Center
> University of Chicago
>
> [[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] Somewhat obscure bug in R 3.4.0 building from source

2017-05-21 Thread Rich Shepard

On Sun, 21 May 2017, Peter Carbonetto wrote:


The error occurs only when I do "make clean" followed by "make" again;
make works the first time.


Peter,

  I suggest you use 'make distclean' rather than 'make clean.' There are
subtle differences between the two, yet the former is more complete. This
might resolve your missing file issue during a second build.

Rich

__
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] Somewhat obscure bug in R 3.4.0 building from source

2017-05-21 Thread Peter Carbonetto
Hi,

I uncovered a bug in installing R 3.4.0 from source in Linux, following the
standard procedure (configure; make; make install). Is this an appropriate
place to report this bug? If not, can you please direct me to the
appropriate place?

The error occurs only when I do "make clean" followed by "make" again; make
works the first time.

The error is a failure to build NEWS.pdf:

Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet,  :
  pdflatex is not available
Calls:  -> texi2pdf -> texi2dvi
Execution halted
make[1]: *** [NEWS.pdf] Error 1
make: [docs] Error 2 (ignored)

and can be reproduced wit the following sequence:

./configure
make
make clean
make

This suggests to me that perhaps "make clean" is not working.

I'm happy to provide more details so that you are able to reproduce the bug.

Thanks,

Peter Carbonetto, Ph.D.
Computational Staff Scientist, Statistics & Genetics
Research Computing Center
University of Chicago

[[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-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] Re: [FORGED] Logical Operators' inconsistent Behavior

2017-05-21 Thread Duncan Murdoch

On 20/05/2017 10:03 PM, Ramnik Bansal wrote:

In the case of logical operations performed with an operand being a
character type, the error is:
"operations are possible only for numeric, logical or complex types"

Now the display of this error message seems to be the OUTCOME of the
fact that implicit coercion is NOT BEING APPLIED INTERNALLY to
character operands in the case of logical operations but is applied to
all other "numeric" type operands. This error message is NOT the
CAUSE.

Well, why not:

F & "abc" return a FALSE because if F & NA can return  FALSE, the
logic being that once an operand is FALSE in case of AND operation
then the output should be False, IRRESPECTIVE of the second operand.
In that case how does it matter if the second operand  is "abc" or
4+5i or NA? The output is deterministically FALSE anyways.

Effectively the point that I want to make is: Treat the character
operand as NA ( except "F", "FALSE", "T", "TRUE" etc which can be
treated as FALSE/TRUE) and then apply the logical operations. Or in
short "Apply implicit coercion on character types as well in case of
logical operations."


For consistency with that point of view, we'd also want

1 + "1"

to equal 2, as it does in some languages.  And maybe "1" + "1" should 
equal 2.


R doesn't do things like that.  It tries for consistency in the 
primitive operations:  you don't get auto-conversion of strings to 
logical/numeric values.  This forces some inconsistencies between the 
primitive operations and explicit coercions like as.logical(), but we 
think that's a good thing.


Duncan Murdoch






On Sat, May 20, 2017 at 4:15 PM, Rolf Turner  wrote:

On 20/05/17 22:42, Duncan Murdoch wrote:


On 20/05/2017 6:39 AM, Rolf Turner wrote:


On 20/05/17 22:18, Duncan Murdoch wrote:


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.)




Actually it *is* mentioned.  From ?logical:


Character strings c("T", "TRUE", "True", "true") are regarded as
true,  c("F", "FALSE", "False", "false") as false, and all others as NA.





I meant that the negative part should be mentioned:  this only works
with an explicit as.logical(), not with implicit coercion.



Ah, I see.  I missed the point.


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] modulus operator?

2017-05-21 Thread Peter Dalgaard
Or maybe Mod(), but please, Heidi, don't expect the rest of the world to guess 
your intentions like that...

-pd

> On 21 May 2017, at 10:27 , Jim Lemon  wrote:
> 
> Hi Heidi,
> I think you are looking for the %% operator. See the Arithmetic help
> page in the base package.
> 
> Jim
> 
> On Sun, May 21, 2017 at 10:28 AM, McGann, Heidi  wrote:
>> 
>> __
>> 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.

-- 
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] modulus operator?

2017-05-21 Thread Jim Lemon
Hi Heidi,
I think you are looking for the %% operator. See the Arithmetic help
page in the base package.

Jim

On Sun, May 21, 2017 at 10:28 AM, McGann, Heidi  wrote:
>
> __
> 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.