Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. cc <- rxSparkConnect(reset = TRUE)
  2. hdfsFileSystem <- RxHdfsFileSystem()
  3. textData <- RxTextData(file = "/share/AirlineDemoSmall/AirlineDemoSmall.csv", missingValueString = "M", stringsAsFactors = TRUE, fileSystem = hdfsFileSystem)
  4. .Summary <- function(keys, data)
  5. {
  6. df <- rxImport(data)
  7. nrow(df)
  8. }
  9.  
  10. # single key
  11. result <- rxExecBy(inData = textData, keys = c("DayOfWeek"), func = .Summary)
  12.  
  13. str(result)
  14. #List of 7
  15. # $ :List of 3
  16. # ..$ keys :List of 1
  17. # .. ..$ : Factor w/ 7 levels "Monday","Sunday",..: 4
  18. # ..$ result: int 78875
  19. # ..$ status:List of 3
  20. # .. ..$ : chr "OK"
  21. # .. ..$ : NULL
  22. # .. ..$ : NULL
  23. # $ :List of 3
  24. # ..$ keys :List of 1
  25. # .. ..$ : Factor w/ 7 levels "Monday","Sunday",..: 6
  26. # ..$ result: int 82987
  27. # ..$ status:List of 3
  28. # .. ..$ : chr "OK"
  29. # .. ..$ : NULL
  30. # .. ..$ : NULL
  31. # $ :List of 3
  32. # ..$ keys :List of 1
  33. # .. ..$ : Factor w/ 7 levels "Monday","Sunday",..: 5
  34. # ..$ result: int 81304
  35. # ..$ status:List of 3
  36. # .. ..$ : chr "OK"
  37. # .. ..$ : NULL
  38. # .. ..$ : NULL
  39. # $ :List of 3
  40. # ..$ keys :List of 1
  41. # .. ..$ : Factor w/ 7 levels "Monday","Sunday",..: 7
  42. # ..$ result: int 86159
  43. # ..$ status:List of 3
  44. # .. ..$ : chr "OK"
  45. # .. ..$ : NULL
  46. # .. ..$ : NULL
  47. # $ :List of 3
  48. # ..$ keys :List of 1
  49. # .. ..$ : Factor w/ 7 levels "Monday","Sunday",..: 1
  50. # ..$ result: int 97975
  51. # ..$ status:List of 3
  52. # .. ..$ : chr "OK"
  53. # .. ..$ : NULL
  54. # .. ..$ : NULL
  55. # $ :List of 3
  56. # ..$ keys :List of 1
  57. # .. ..$ : Factor w/ 7 levels "Monday","Sunday",..: 3
  58. # ..$ result: int 77725
  59. # ..$ status:List of 3
  60. # .. ..$ : chr "OK"
  61. # .. ..$ : NULL
  62. # .. ..$ : NULL
  63. # $ :List of 3
  64. # ..$ keys :List of 1
  65. # .. ..$ : Factor w/ 7 levels "Monday","Sunday",..: 2
  66. # ..$ result: int 94975
  67. # ..$ status:List of 3
  68. # .. ..$ : chr "OK"
  69. # .. ..$ : NULL
  70. # .. ..$ : NULL
  71.  
  72. # multi keys
  73. result <- rxExecBy(inData = textData, keys = c("DayOfWeek", "ArrDelay"), func = .Summary)
  74.  
  75. length(result)
  76. #[1] 3233
  77.  
  78. str(result[[1]])
  79. #List of 3
  80. # $ keys :List of 2
  81. # ..$ : Factor w/ 7 levels "Monday","Sunday",..: 4
  82. # ..$ : int 388
  83. # $ result: int 2
  84. # $ status:List of 3
  85. # ..$ : chr "OK"
  86. # ..$ : NULL
  87. # ..$ : NULL
  88.  
  89. rxSparkDisconnect(cc)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement