[R] Logical vectors

Stephen Liu satimis at yahoo.com
Thu Nov 4 09:16:07 CET 2010


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






More information about the R-help mailing list