Reputation: 357
Basically, I want to check if the square root of a number is an integer, so I tried the following function:
is.integer(sqrt(4))
The expected value is TRUE
whereas the actual result is FALSE
. I have read some other posts and it seems I need to use L
to force into an integer. However, not sure how should I make it work in my case.
Upvotes: 3
Views: 349
Reputation: 16797
Yes. Even:
is.integer(1)
## [1] FALSE
because the type (opposed to the value) is not integer. Look at the help ?is.integer
. A function is.wholenumber
is shown there:
is.wholenumber <-
function(x, tol = .Machine$double.eps^0.5)
abs(x - round(x)) < tol
is.wholenumber(sqrt(4))
## [1] TRUE
Upvotes: 7