[R] integer

Uwe Ligges ligges at statistik.uni-dortmund.de
Tue Nov 2 15:44:01 CET 2004


Göran Broström wrote:

> On Tue, Nov 02, 2004 at 11:36:27AM +0100, Uwe Ligges wrote:
> 
>>Ludovic Tambour wrote:
>>
>>
>>>Hello,
>>>
>>>I need to use "R" to determine parameters which are integers. How I can do
>>>this, please ?
>>
>>What so you mean with "parameters"? In which context?
>>
>>To check whether a numeric vector "x" contains only integers, you can try
>>
>>all.equal(as.integer(x), x)
> 
> 
> I don't think so:
> 
> 
>>x <- as.double(c(1, 2))
>>y <- as.integer(c(1, 2))
>>all.equal(x, y)
> 
> [1] TRUE
> 
> But,
> 
> 
>>identical(x, y)
> 
> [1] FALSE

[The story was completely different from the stuff I guessed, so all 
further communication related to this thread is "academic".]

Göran,

yes, as expected.


> On the other hand, why not use 
> 
> 
>>is.integer(x)
> 
> [1] FALSE
> 
>>is.integer(y)
> 
> [1] TRUE
> 
> because I think that a numeric vector can't have a mix of integer and
> non-integer elements. With a list it's a different story.

Yes.

My guees was that the asker tried to identify integers such as 2, 3 in 
contrast to 2.1, 3.1, ...and you won't know it by looking at R's storage 
mode (my guess was that the asker was not interested in the storage 
mode, but in the nature of the numbers!).
Note that is.integer(1) is FALSE!!!

The given usage of all.equal() helps to identify 1 as an integer, but 
not 1.1...

Uwe

> Göran




More information about the R-help mailing list