How can I test if the square root of a number is an integer using R?
The following all evaluate to FALSE
.
is.integer( sqrt(25) )
is.integer( sqrt(25L) )
How can I test if the square root of a number is an integer using R?
The following all evaluate to FALSE
.
is.integer( sqrt(25) )
is.integer( sqrt(25L) )
Ok, I found a work around, but I'm not sure if it's efficient or even robust to using more exotic numbers.
25 %% sqrt(25) == 0
Evaluates to TRUE
.
Perhaps a better way of doing this would be:
sqrt(25) %% 1 == 0
Which also evaluates to TRUE
. Adapted from this answer.