[R] Bug in "is" ?

Yihui Xie xieyihui at gmail.com
Wed Sep 24 06:54:34 CEST 2008


Yes, everyone will agree "7" is an integer, but I don't think
computers will agree too :-) R thinks it's a double-precision number,
except when you explicitly specify it as an integer (say,
as.integer()).

> class(7)
[1] "numeric"

> is.double(7)
[1] TRUE

Regards,
Yihui
--
Yihui Xie <xieyihui at gmail.com>
Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086
Mobile: +86-15810805877
Homepage: http://www.yihui.name
School of Statistics, Room 1037, Mingde Main Building,
Renmin University of China, Beijing, 100872, China



On Wed, Sep 24, 2008 at 12:40 PM,  <ctu at bigred.unl.edu> wrote:
> Hi R users
> Is there anything wrong in "is" function? (R 2.7.2)
> I believe that everyone will agree that "7" is an integer, right? but why R
> shows 7 is not an integer
>
>> is.integer(7)
>
> [1] FALSE
>>
>> is(7,"integer")
>
> [1] FALSE
>>
>> is(as.integer(7), "integer")
>
> [1] TRUE
>
> Thank you very much in advance
> Chunhao
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list