From: Sundar Dorai-Raj <sundar.dorai-raj_at_pdf.com>

Date: Fri 01 Jul 2005 - 01:39:11 EST

R-help@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 Received on Fri Jul 01 01:45:12 2005

Date: Fri 01 Jul 2005 - 01:39:11 EST

Tuszynski, Jaroslaw W. wrote:

*> Hi,
**>
*

> I was trying to figure out if there is a function in R that tests if R

*> object contains only integers. I though "is.integer" would be it, but this
**> function only checks "whether its argument is of integer type or not". As a
**> result
**> x = (1:5)^2
**> is.integer(x)
**> Returns false. Of course I can write my own function like
**> "!any(x!=as.integer(x))" but I am just trying to make sure I am not
**> reinventing the wheel.
**>
**> Jarek
*

Since "^" returns a double, it's no wonder is.integer(x) didn't work as you expected. Perhaps you want something more like

is.int <- function(x, tol = .Machine$double.eps) {

(x - floor(x)) < tol

}

is.int((1:5)^2)

**HTH,
**
--sundar

R-help@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 Received on Fri Jul 01 01:45:12 2005

*
This archive was generated by hypermail 2.1.8
: Fri 03 Mar 2006 - 03:33:08 EST
*