Guest User

Untitled

a guest
Nov 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. library(rmr2)
  2. library(rhdfs)
  3.  
  4. setwd('/C:UsersDesktopNew folder' )
  5. data<-read.csv("datafile.csv")
  6. #head(data)
  7. hdfs.init()
  8. data.values <- to.dfs(data)
  9.  
  10.  
  11. data.map.fn <- function(k,v)
  12. {
  13. p <- which((as.numeric(v[,4]) == 1) & ((as.numeric(v[,8]) >= 500) & (as.numeric(v[,8]) <= 565))
  14. keyval(v[p,],v[p,c(4,8)])
  15. }
  16.  
  17. data.reduce.fn <- function(k,v)
  18. {
  19. keyval(k,(unlist(v)))
  20. }
  21.  
  22. # study mapreduce function and pass appropriate inputs and ouputs.
  23.  
  24. dataex <- mapreduce(input= data.values ,
  25. map = data.map.fn,
  26. reduce = data.reduce.fn)
  27.  
  28. totalvar<-from.dfs(dataex)
  29. o<- unlist(totalvar[2])
  30. l <- length(o)/2
  31. totalvar #AT this point return is a NULL
  32.  
  33. k <- unlist(totalvar)
  34. l <- length(k)/2
  35. y<-matrix(k,nrow=l,ncol=2,byrow=TRUE)
  36.  
  37.  
  38.  
  39. k <- rbind(as.data.frame(totalvar[2]))
  40. j <- as.data.frame(k[!duplicated(as.data.frame(k)),])
  41.  
  42.  
  43. y<-matrix(k,nrow=l,ncol=10,byrow=FALSE)
  44. write.csv(y,'mapreducedfile.csv')
Add Comment
Please, Sign In to add comment