# isInteger: Test For Integrity In ttutils: Utility functions

## Description

`isInteger` tests if a given number is an integer.

## Usage

 `1` ```isInteger(n, tol = .Machine\$double.eps) ```

## Arguments

 `n` a vector or an array of values to be tested. `tol` a numeric value giving the tolerance level.

## Details

As opposed to `is.integer` this function tests for integrity of a given value, rather than being of type `integer`.

In R integers are specified by the suffix `L` (e.g. `1L`), whereas all other numbers are of class `numeric` independent of their value. The function `is.integer` does not test whether a given variable has an integer value, but whether it belongs to the class `integer`.

In contrast, the function `isInteger` compares the difference between its argument and its rounded argument. If it is smaller than some predefined tolerance level, the variable is regarded as integer.

## Value

`TRUE` if the argument `n` has an integer value, `FALSE` otherwise.

## Note

The R function `c` concatenates its argument and forms a vector. In doing so, it coerces the values to a common type. Hence, attention has to be paid, because `isInteger` may give some unexpected results in this case. The R command `list`, however, does not coerce its arguments (see the example).

## Author(s)

Thorn Thaler

`is.integer`

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15``` ```# isInteger tests if the _value_ of a variable is an integer # 'c' as opposed to 'list' coerces its arguments! isInteger(c("test", 1, 2, 2.1)) # FALSE FALSE FALSE FALSE isInteger(list("test", 1, 2, 2.1)) # FALSE TRUE TRUE FALSE class(1L) # integer typeof(1L) # integer class(1) # numeric typeof(1) # double # is.integer tests if the _class_ of a variable is 'integer' is.integer(c("test", 1, 2)) # FALSE is.integer(list("test", 1, 2)) # FALSE is.integer(1) # FALSE is.integer(1L) # TRUE ```

### Example output

``` test     1     2   2.1
FALSE FALSE FALSE FALSE
 FALSE  TRUE  TRUE FALSE
 "integer"
 "integer"
 "numeric"
 "double"
 FALSE
 FALSE
 FALSE
 TRUE
```

ttutils documentation built on May 1, 2019, 11:32 p.m.