Re: [R] Logical vectors
On Wed, 3 Nov 2010, Stephen Liu wrote: [snip] 2) x [1] 1 2 3 4 5 temp - x 1 temp [1] FALSE TRUE TRUE TRUE TRUE Why NOT temp [1] TRUE FALSE FALSE FALSE FALSE ? Maybe because of the definition of (greater (!) than)? Or do you expect 1 to be greater than 1 and not greater than 2, 3, 4, and 5? Regards -- Gerrit - AOR Dr. Gerrit Eichner Mathematical Institute, Room 212 gerrit.eich...@math.uni-giessen.de Justus-Liebig-University Giessen Tel: +49-(0)641-99-32104 Arndtstr. 2, 35392 Giessen, Germany Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner __ R-help@r-project.org mailing list 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] Logical vectors
On Wed, Nov 3, 2010 at 10:50 PM, Stephen Liu sati...@yahoo.com wrote: Hi folks, Pls help me to understand follow; An Introduction to R 2.4 Logical vectors http://cran.r-project.org/doc/manuals/R-intro.html#R-and-statistics 1) x [1] 1 2 3 4 5 a vector, x, is defined with 5 elements, {1, 2, 3, 4, 5} temp - x != 1 perform the logical test that x does not equal 1 returning either TRUE or FALSE. 1 = 1 so TRUE, 2 != 1 so FALSE, etc. next we assign *the results* of the logical test to the vector 'temp' temp [1] FALSE TRUE TRUE TRUE TRUE print the vector to screen 2) x [1] 1 2 3 4 5 note that x has not changed here, we assigned to temp, not to x. temp - x 1 now we assign the results of the logical test, x 1 {1 = 1 so FALSE, 2 1 so TRUE, 3 1 so TRUE, 4 1 so TRUE, 5 1 so TRUE} we assign these results to a vector, 'temp'. This *new* assignment overwrites the old vector 'temp' temp [1] FALSE TRUE TRUE TRUE TRUE print temp to screen, this is the results of our second logical test (x 1). Why NOT temp [1] TRUE FALSE FALSE FALSE FALSE My best guess of where you got confused is that we assigned the results to 'temp', so 'x' remained unchanged {1, 2, 3, 4, 5}, or that you confused '-' which is the assignment operator in R, to less than negative... *OR* less than or equal. We could write this equivalently: 1:5 1 [1] FALSE TRUE TRUE TRUE TRUE this was the logical test, whose results were assigned to the vector, temp. assign(x = temp, value = 1:5 1) using the assign function (not often recommended) to avoid any confusion with the assignment operator, -. temp [1] FALSE TRUE TRUE TRUE TRUE print to screen HTH, Josh ? TIA B.R. Stephen L __ R-help@r-project.org mailing list 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. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ __ R-help@r-project.org mailing list 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] Logical vectors
Hi Gerrit, Thanks for your advice. In; 2.4 Logical vectors http://cran.r-project.org/doc/manuals/R-intro.html#R-and-statistics It states:- The logical operators are , =, , =, == for exact equality and != for inequality # exact equality != # inequality I did follows; x - 1:5 x [1] 1 2 3 4 5 temp - x != 1 temp [1] FALSE TRUE TRUE TRUE TRUE That is correct. rm(temp) temp - x 1 temp [1] FALSE TRUE TRUE TRUE TRUE That seems not correct. My understanding is; [1] TRUE FALSE FALSE FALSE FALSE B.R. Stephen L - Original Message From: Gerrit Eichner gerrit.eich...@math.uni-giessen.de To: Stephen Liu sati...@yahoo.com Cc: r-help@r-project.org Sent: Thu, November 4, 2010 2:34:55 PM Subject: Re: [R] Logical vectors On Wed, 3 Nov 2010, Stephen Liu wrote: [snip] 2) x [1] 1 2 3 4 5 temp - x 1 temp [1] FALSE TRUE TRUE TRUE TRUE Why NOT temp [1] TRUE FALSE FALSE FALSE FALSE ? Maybe because of the definition of (greater (!) than)? Or do you expect 1 to be greater than 1 and not greater than 2, 3, 4, and 5? Regards -- Gerrit - AOR Dr. Gerrit Eichner Mathematical Institute, Room 212 gerrit.eich...@math.uni-giessen.de Justus-Liebig-University Giessen Tel: +49-(0)641-99-32104 Arndtstr. 2, 35392 Giessen, Germany Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner - __ R-help@r-project.org mailing list 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] Logical vectors
Hi Joshua, Thanks for your advice. assign(x = temp, value = 1:5 1) using the assign function (not often recommended) to avoid any confusion with the assignment operator, -. temp [1] FALSE TRUE TRUE TRUE TRUE I got it. Thanks B.R. Stephen L - Original Message From: Joshua Wiley jwiley.ps...@gmail.com To: Stephen Liu sati...@yahoo.com Cc: r-help@r-project.org Sent: Thu, November 4, 2010 2:46:15 PM Subject: Re: [R] Logical vectors On Wed, Nov 3, 2010 at 10:50 PM, Stephen Liu sati...@yahoo.com wrote: Hi folks, Pls help me to understand follow; An Introduction to R 2.4 Logical vectors http://cran.r-project.org/doc/manuals/R-intro.html#R-and-statistics 1) x [1] 1 2 3 4 5 a vector, x, is defined with 5 elements, {1, 2, 3, 4, 5} temp - x != 1 perform the logical test that x does not equal 1 returning either TRUE or FALSE. 1 = 1 so TRUE, 2 != 1 so FALSE, etc. next we assign *the results* of the logical test to the vector 'temp' temp [1] FALSE TRUE TRUE TRUE TRUE print the vector to screen 2) x [1] 1 2 3 4 5 note that x has not changed here, we assigned to temp, not to x. temp - x 1 now we assign the results of the logical test, x 1 {1 = 1 so FALSE, 2 1 so TRUE, 3 1 so TRUE, 4 1 so TRUE, 5 1 so TRUE} we assign these results to a vector, 'temp'. This *new* assignment overwrites the old vector 'temp' temp [1] FALSE TRUE TRUE TRUE TRUE print temp to screen, this is the results of our second logical test (x 1). Why NOT temp [1] TRUE FALSE FALSE FALSE FALSE My best guess of where you got confused is that we assigned the results to 'temp', so 'x' remained unchanged {1, 2, 3, 4, 5}, or that you confused '-' which is the assignment operator in R, to less than negative... *OR* less than or equal. We could write this equivalently: 1:5 1 [1] FALSE TRUE TRUE TRUE TRUE this was the logical test, whose results were assigned to the vector, temp. assign(x = temp, value = 1:5 1) using the assign function (not often recommended) to avoid any confusion with the assignment operator, -. temp [1] FALSE TRUE TRUE TRUE TRUE print to screen HTH, Josh ? TIA B.R. Stephen L __ R-help@r-project.org mailing list 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. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ __ R-help@r-project.org mailing list 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] Logical vectors
On Thu, 4 Nov 2010, Stephen Liu wrote: [snip] In; 2.4 Logical vectors http://cran.r-project.org/doc/manuals/R-intro.html#R-and-statistics It states:- The logical operators are , =, , =, == for exact equality and != for inequality # exact equality != # inequality [snip] Hello, Stephen, in my understanding of the sentence The logical operators are , =, , =, == for exact equality and != for inequality the phrase exact equality refers to the operator ==, i. e. to the last element == in the enumeration (, =, , =, ==), and not to its first. Regards -- Gerrit - AOR Dr. Gerrit Eichner Mathematical Institute, Room 212 gerrit.eich...@math.uni-giessen.de Justus-Liebig-University Giessen Tel: +49-(0)641-99-32104 Arndtstr. 2, 35392 Giessen, Germany Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner __ R-help@r-project.org mailing list 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] Logical vectors
On 04-Nov-10 08:56:42, Gerrit Eichner wrote: On Thu, 4 Nov 2010, Stephen Liu wrote: [snip] In; 2.4 Logical vectors http://cran.r-project.org/doc/manuals/R-intro.html#R-and-statistics It states:- The logical operators are , =, , =, == for exact equality and != for inequality # exact equality != # inequality [snip] Hello, Stephen, in my understanding of the sentence The logical operators are , =, , =, == for exact equality and != for inequality the phrase exact equality refers to the operator ==, i. e. to the last element == in the enumeration (, =, , =, ==), and not to its first. Regards -- Gerrit This indicates that the sentence can be mis-read. It should be cured by a small change in punctuation (hence I copy to R-devel): The logical operators are , =, , =; == for exact equality; and != for inequality Hoping this helps! Ted. E-Mail: (Ted Harding) ted.hard...@wlandres.net Fax-to-email: +44 (0)870 094 0861 Date: 04-Nov-10 Time: 09:08:37 -- XFMail -- __ R-help@r-project.org mailing list 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] Logical vectors
H Gerrit, the phrase exact equality refers to the operator ==, i. e. to the last element == in the enumeration (, =, , =, ==), and not to its first. x - 1:5 x [1] 1 2 3 4 5 temp -x == 1 temp [1] TRUE FALSE FALSE FALSE FALSE I got it thanks. B.R. Stephen L - Original Message From: Gerrit Eichner gerrit.eich...@math.uni-giessen.de To: Stephen Liu sati...@yahoo.com Cc: r-help@r-project.org Sent: Thu, November 4, 2010 4:56:42 PM Subject: Re: [R] Logical vectors On Thu, 4 Nov 2010, Stephen Liu wrote: [snip] In; 2.4 Logical vectors http://cran.r-project.org/doc/manuals/R-intro.html#R-and-statistics It states:- The logical operators are , =, , =, == for exact equality and != for inequality # exact equality != # inequality [snip] Hello, Stephen, in my understanding of the sentence The logical operators are , =, , =, == for exact equality and != for inequality the phrase exact equality refers to the operator ==, i. e. to the last element == in the enumeration (, =, , =, ==), and not to its first. Regards -- Gerrit - AOR Dr. Gerrit Eichner Mathematical Institute, Room 212 gerrit.eich...@math.uni-giessen.de Justus-Liebig-University Giessen Tel: +49-(0)641-99-32104 Arndtstr. 2, 35392 Giessen, Germany Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner - __ R-help@r-project.org mailing list 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] Logical vectors
Hi Ted, Thanks for your advice and the correction on the document concerned. B.R. Stephen L - Original Message From: ted.hard...@wlandres.net ted.hard...@wlandres.net To: r-help@r-project.org Cc: Stephen Liu sati...@yahoo.com; R-Devel r-de...@stat.math.ethz.ch Sent: Thu, November 4, 2010 5:08:42 PM Subject: Re: [R] Logical vectors On 04-Nov-10 08:56:42, Gerrit Eichner wrote: On Thu, 4 Nov 2010, Stephen Liu wrote: [snip] In; 2.4 Logical vectors http://cran.r-project.org/doc/manuals/R-intro.html#R-and-statistics It states:- The logical operators are , =, , =, == for exact equality and != for inequality # exact equality != # inequality [snip] Hello, Stephen, in my understanding of the sentence The logical operators are , =, , =, == for exact equality and != for inequality the phrase exact equality refers to the operator ==, i. e. to the last element == in the enumeration (, =, , =, ==), and not to its first. Regards -- Gerrit This indicates that the sentence can be mis-read. It should be cured by a small change in punctuation (hence I copy to R-devel): The logical operators are , =, , =; == for exact equality; and != for inequality Hoping this helps! Ted. E-Mail: (Ted Harding) ted.hard...@wlandres.net Fax-to-email: +44 (0)870 094 0861 Date: 04-Nov-10 Time: 09:08:37 -- XFMail -- __ R-help@r-project.org mailing list 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] Logical vectors
Hi folks, Pls help me to understand follow; An Introduction to R 2.4 Logical vectors http://cran.r-project.org/doc/manuals/R-intro.html#R-and-statistics 1) x [1] 1 2 3 4 5 temp - x != 1 temp [1] FALSE TRUE TRUE TRUE TRUE 2) x [1] 1 2 3 4 5 temp - x 1 temp [1] FALSE TRUE TRUE TRUE TRUE Why NOT temp [1] TRUE FALSE FALSE FALSE FALSE ? TIA B.R. Stephen L __ R-help@r-project.org mailing list 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.