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
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.eichner at math.uni-giessen.de Justus-Liebig-University Giessen Tel: +49-(0)641-99-32104 Arndtstr. 2, 35392 Giessen, Germany Fax: +49-(0)641-99-32109 http://www.uni-giessen.de/cms/eichner
On Wed, Nov 3, 2010 at 10:50 PM, Stephen Liu <satimis at 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 5a vector, x, is defined with 5 elements, {1, 2, 3, 4, 5}>> temp <- x != 1perform 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 ?TRUEprint the vector to screen>> > > > 2) >> x > [1] 1 2 3 4 5note that x has not changed here, we assigned to temp, not to x.>> temp <- x > 1now 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 ?TRUEprint temp to screen, this is the results of our second logical test (x > 1).> > > Why NOT >> temp > [1] TRUE ?FALSE ?FALSE FALSE ?FALSEMy 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 at 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/
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 FALSEB.R. Stephen L ----- Original Message ---- From: Gerrit Eichner <Gerrit.Eichner at math.uni-giessen.de> To: Stephen Liu <satimis at yahoo.com> Cc: r-help at 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.eichner at math.uni-giessen.de Justus-Liebig-University Giessen Tel: +49-(0)641-99-32104 Arndtstr. 2, 35392 Giessen, Germany Fax: +49-(0)641-99-32109 http://www.uni-giessen.de/cms/eichner ---------------------------------------------------------------------
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.eichner at math.uni-giessen.de Justus-Liebig-University Giessen Tel: +49-(0)641-99-32104 Arndtstr. 2, 35392 Giessen, Germany Fax: +49-(0)641-99-32109 http://www.uni-giessen.de/cms/eichner
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.Eichner at math.uni-giessen.de> To: Stephen Liu <satimis at yahoo.com> Cc: r-help at 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.eichner at math.uni-giessen.de Justus-Liebig-University Giessen Tel: +49-(0)641-99-32104 Arndtstr. 2, 35392 Giessen, Germany Fax: +49-(0)641-99-32109 http://www.uni-giessen.de/cms/eichner ---------------------------------------------------------------------
Maybe Matching Threads
- Logical vectors
- effects & lme4: error since original data frame notfoundWASeffects: error when original data frame is missing
- effects & lme4: error since original data frame not found WASeffects: error when original data frame is missing
- Problem with regression line
- effects: error when original data frame is missing