[R] Testing for whole numbers

Tamas Papp tpapp at axelero.hu
Thu Apr 17 16:47:30 CEST 2003


Is there a way in R to test if a given number is an integer, ie a
whole number? I am not referring to the data type of a number, but to
its value.

That is to say, is.whole(pi-pi+2) would be TRUE, whereas is.whole(4/3)
would be false. At the moment I am using

is.whole <- function(a) { floor(a)==a }

which is OK for real numbers, but not for complex ones (a+bi would be
a whole number if both a and b are whole). Although it's obvious to
test for the type of the argument and treat it accordingly, I am sure
that there is a function for that in R.

My questions are:

1. Is there a predefined function for this? I am not trying to
reinvent the wheel, but I have searched help and found nothing
relevant.

2. Would it make sense to propose the extension of floor, trunc etc to
complex numbers? It would certainly make my life easier in many
situations.

Regards,

Tamas Papp

-- 
Tamás K. Papp
E-mail: tpapp at axelero.hu (preferred, especially for large messages)
        tpapp at westel900.net
Please try to send only (latin-2) plain text, not HTML or other garbage.



More information about the R-help mailing list