Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. library(data.table)
  2. fis.na = data.table:::fis.na
  3. N = 1e8
  4. set.seed(108)
  5. N_na = 1e3
  6. N_nan = 1e3
  7.  
  8. # integer
  9. x = sample(N)
  10. x[sample(N, N_na)] = NA
  11. system.time(ans1<-is.na(x))
  12. system.time(ans2<-fis.na(x))
  13. identical(ans1, ans2)
  14.  
  15. # raw
  16. x = as.raw(1:N)
  17. system.time(ans1<-is.na(x))
  18. system.time(ans2<-fis.na(x))
  19. identical(ans1, ans2)
  20.  
  21. # string
  22. x = paste0("id", 1:N)
  23. x[sample(N, N_na)] = NA
  24. system.time(ans1<-is.na(x))
  25. system.time(ans2<-fis.na(x))
  26. identical(ans1, ans2)
  27.  
  28. # double
  29.  
  30. # there is no function for "NA but not NaN"
  31. is.na(NaN)
  32. is.nan(NA)
  33. is.na.only = function(x) is.na(x) & !is.nan(x)
  34.  
  35. x = runif(N)
  36. x[sample(N, N_na)] = NA
  37. x[sample(N, N_nan)] = NaN
  38. system.time(ans1<-is.na(x))
  39. system.time(ans2<-fis.na(x))
  40. identical(ans1, ans2)
  41.  
  42. x = runif(N)
  43. x[sample(N, N_na)] = NA
  44. x[sample(N, N_nan)] = NaN
  45. system.time(ans1<-is.na.only(x))
  46. system.time(ans2<-fis.na(x, NA))
  47. identical(ans1, ans2)
  48.  
  49. x = runif(N)
  50. x[sample(N, N_na)] = NA
  51. x[sample(N, N_nan)] = NaN
  52. system.time(ans1<-is.nan(x))
  53. system.time(ans2<-fis.na(x, NaN))
  54. identical(ans1, ans2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement