Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ```r
- x <- 1:4 + 0.1
- (x <- x - 0.1) # looks like integer, doesn't it?
- ```
- ```
- ## [1] 1 2 3 4
- ```
- ```r
- ## here's the suggestion from the help to test if x contains integers
- is.wholenumber <-
- function(x, tol = .Machine$double.eps^0.5) abs(x - round(x)) < tol
- ## so are they whole numbers?
- is.wholenumber(x)
- ```
- ```
- ## [1] TRUE TRUE TRUE TRUE
- ```
- ```r
- ## apparently YES!
- ## but not the whole numbers they appear to be?
- as.integer(x)
- ```
- ```
- ## [1] 1 2 3 3
- ```
- ```r
- trunc(x)
- ```
- ```
- ## [1] 1 2 3 3
- ```
- ```r
- floor(x)
- ```
- ```
- ## [1] 1 2 3 3
- ```
- ```r
- LETTERS[x]
- ```
- ```
- ## [1] "A" "B" "C" "C"
- ```
- ```r
- ## I have a better idea!
- is.integery <-
- function(x, tol = .Machine$double.eps^0.5) all(abs(x - trunc(x)) < tol)
- is.integery(x)
- ```
- ```
- ## [1] FALSE
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement