From macrakis at alum.mit.edu  Wed Apr 22 22:30:36 2009
From: macrakis at alum.mit.edu (Stavros Macrakis)
Date: Wed, 22 Apr 2009 16:30:36 -0400
Subject: [Rd] 'is.integer' (PR#13671)
In-Reply-To: <20090422174516.2EB1928321BF@mail.pubhealth.ku.dk>
References: <20090422174516.2EB1928321BF@mail.pubhealth.ku.dk>
Message-ID: <8b356f880904221330r2c2776cid12036442511b216@mail.gmail.com>

Dear R experts,

You are being a bit harsh on this user. He simply doesn't understand
the distinction between "object of type integer" and "integer-valued
object", which is actually fairly subtle.

On Wed, Apr 22, 2009 at 1:45 PM,  <hzambran.newsgroups at gmail.com> wrote:
> This is a very simple function that seems not to be working, according to the
> definition given by '?is.integer'.
...
>> is.integer(1)
> [1] FALSE
>
> and 1 is obviously an integer value.

The is.integer function is correctly documented to check whether
objects are of *type* integer, thus:

     is.integer( 1L ) => TRUE

In R, objects of type integer are only created with literals of the
form 999L; as the output of some functions when the input is integral
(e.g. sort, unique, rev, ...); as the output of some functions which
return index values or differences of index values (which, grep, rle,
...); and the output of a few other functions in certain cases (seq).

Most numbers in R are floating-point numbers (type double), and
determining whether their value is integral is rather subtle.

For example, consider the vector 1+1000^-(1:6).  In floating-point
arithmetic, the first 5 values are distinguishable from the integer 1,
but the 6th is not, though of course the *mathematical* number
1+1000^-6 is not integral.  Now consider 1e40, which has the property
that floor(x)==x==ceiling(x), which you might think characterizes an
integer;  but it also has the property that x+1 == x.  Similarly for
1/3 * 1e40.

In other words, it is really a rather subtle question whether a
floating-point number "represents" an integer....

       -s



[Rd] 'is.integer' (PR#13671)
Stavros Macrakis