Hi R users I have a simple question to ask. Why am I getting FALSE on this>is.integer(10)[1] FALSE 10 is a integer number. Thanks in advance. M
Becaues is.integer shows the internal representation, which is not an integer but a double (real number). Some functions create integer vectors, for example the : notation:> is.integer(1:10)[1] TRUE You can create an integer vector with the integer() function:> integer(10)[1] 0 0 0 0 0 0 0 0 0 0> is.integer(integer(10))[1] TRUE Gabor On Tue, Jan 24, 2006 at 09:29:51PM -0600, Taka Matzmoto wrote:> Hi R users > I have a simple question to ask. > Why am I getting FALSE on this > > >is.integer(10) > [1] FALSE > > 10 is a integer number. > > Thanks in advance. > > M > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html-- Csardi Gabor <csardi at rmki.kfki.hu> MTA RMKI, ELTE TTK
S Poetry page 125. Patrick Burns patrick at burns-stat.com +44 (0)20 8525 0696 http://www.burns-stat.com (home of S Poetry and "A Guide for the Unwilling S User") Taka Matzmoto wrote:>Hi R users >I have a simple question to ask. >Why am I getting FALSE on this > > > >>is.integer(10) >> >> >[1] FALSE > >10 is a integer number. > >Thanks in advance. > >M > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > > > >
Hi Numbers are normaly stored as double so you has to declare it as an integer.> str(10)num 10> str(as.integer(10))int 10>HTH Petr On 24 Jan 2006 at 21:29, Taka Matzmoto wrote: From: "Taka Matzmoto" <sell_mirage_ne at hotmail.com> To: r-help at stat.math.ethz.ch Date sent: Tue, 24 Jan 2006 21:29:51 -0600 Subject: [R] is.integer() function> Hi R users > I have a simple question to ask. > Why am I getting FALSE on this > > >is.integer(10) > [1] FALSE > > 10 is a integer number. > > Thanks in advance. > > M > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.htmlPetr Pikal petr.pikal at precheza.cz
On Tue, 24 Jan 2006, Taka Matzmoto wrote:> Hi R users > I have a simple question to ask. > Why am I getting FALSE on this > >> is.integer(10) > [1] FALSE > > 10 is a integer number.is.integer() asks how a number is stored, not whether the number happens to be an integer. Explicit numbers typed into R are stored as double precision even if they happen to be whole numbers. This is historical but is also useful: the double precision type can hold integers up to 2^52 exactly and the integer type can only hold integers up to 2^31. -thomas