Advertisement
Guest User

Untitled

a guest
May 27th, 2015
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1.  
  2. ```r
  3. x <- 1:4 + 0.1
  4. (x <- x - 0.1) # looks like integer, doesn't it?
  5. ```
  6.  
  7. ```
  8. ## [1] 1 2 3 4
  9. ```
  10.  
  11. ```r
  12. ## here's the suggestion from the help to test if x contains integers
  13. is.wholenumber <-
  14. function(x, tol = .Machine$double.eps^0.5) abs(x - round(x)) < tol
  15.  
  16. ## so are they whole numbers?
  17. is.wholenumber(x)
  18. ```
  19.  
  20. ```
  21. ## [1] TRUE TRUE TRUE TRUE
  22. ```
  23.  
  24. ```r
  25. ## apparently YES!
  26.  
  27. ## but not the whole numbers they appear to be?
  28. as.integer(x)
  29. ```
  30.  
  31. ```
  32. ## [1] 1 2 3 3
  33. ```
  34.  
  35. ```r
  36. trunc(x)
  37. ```
  38.  
  39. ```
  40. ## [1] 1 2 3 3
  41. ```
  42.  
  43. ```r
  44. floor(x)
  45. ```
  46.  
  47. ```
  48. ## [1] 1 2 3 3
  49. ```
  50.  
  51. ```r
  52. LETTERS[x]
  53. ```
  54.  
  55. ```
  56. ## [1] "A" "B" "C" "C"
  57. ```
  58.  
  59. ```r
  60. ## I have a better idea!
  61. is.integery <-
  62. function(x, tol = .Machine$double.eps^0.5) all(abs(x - trunc(x)) < tol)
  63.  
  64. is.integery(x)
  65. ```
  66.  
  67. ```
  68. ## [1] FALSE
  69. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement