[R] how to judge a virable is a integer?

Berend Hasselman bhh at xs4all.nl
Sat Oct 18 12:58:48 CEST 2014


On 18-10-2014, at 12:41, PO SU <rhelpmaillist at 163.com> wrote:

> 
> 
> Dear usRers,
>    I want to judge virable is or not a integer?
>   e.g.  is.integer(1)  FALSE   because it is a numeric, but i want it's true.
> as.integer may not be used. because i don't know a is 1 or 1.1.
> 

is.integer is surely what you need if you wish to test if a variable is integer.
See this

# a <- 1
# b <- 1L

# is.integer(a)
[1] FALSE

# is.integer(b)
[1] TRUE

See the help for is.integer to see how you can test for a wholenumber, which might be what you want.

Berend



More information about the R-help mailing list