[R] testing for integer
Bob Wheeler
bwheeler at echip.com
Sun Feb 25 03:13:33 CET 2001
Everything is double. You might try n==floor(n).
Faheem Mitha wrote:
>
> Dear People,
>
> Consider the following fragment of R code
>
> choose <- function(n,r)
> {
> if( is.integer(n) && is.integer(r) && n > 0 && r >= 0 )
> {
> .C("choose",as.double(n),as.double(r),comb = double(1))$comb
> }
> else stop("n must be a positive integer and r a non-negative integer.")
> }
>
> This is a practice function (n choose r), which I wrote using a call to C
> code. Unfortunately, there is the following problem. I thought I would put
> in error checking for whether the arguments were integers. However,
> is.integer(1), for example, returns FALSE. However is.numeric(1) returns
> TRUE. It seems that explicit coercion is required for this ie.
> is.integer(as.integer(1)) returns true However, I can't use as.integer,
> because it is too aggressive for just error checking: it rounds off the
> value to the greatest integer less than. Can anyone suggest a suitable
> method of checking for an integer in this case?
>
> Sincerely, Faheem Mitha.
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
--
Bob Wheeler --- (Reply to: bwheeler at echip.com)
ECHIP, Inc.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list