Guest User

Untitled

a guest
Jan 17th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. Text 1 Text 2 Text 3 Text 4
  2. Bob Aba Abb Abc
  3. Robert Aba Abb Abc
  4. Fred Abd Abe Abf
  5. Martin Abg Abh Abi
  6.  
  7. Text 1 Text 1a Text 2 Text 3 Text 4 Text 4a
  8. Bob Robert Aba Abb Abc Abd
  9. Fred NA Abd Abe Abf NA
  10. Martin NA Abg Abh Abi NA
  11.  
  12. join=join(Data1, Data2, by = c('Text2'), type = "full", match = "all")
  13.  
  14. MyDataAgg=aggregate(MyData, by=list(MyData$Text1), c)
  15.  
  16. 1 -none- numeric
  17. 1 -none- numeric
  18. 2 -none- numeric
  19.  
  20. $ Initials :List of 12505
  21. ..$ 1 : int 62
  22. ..$ 2 : int 310
  23. ..$ 3 : int 504
  24.  
  25. do.call(plyr::rbind.fill,by(dat,list(dat$Text2,dat$Text3),
  26. function(d){
  27. ## change all other columns to a one row data.frame
  28. dd <- as.data.frame(as.list(rapply(d[,-c(2,3)],as.character)))
  29. ## the tricky part : add 1 to a name like Text1 to become Text11 ,
  30. ## this is import to join data.frames formed by by
  31. names(dd) <- gsub('(Text[0-9]$)','\11',names(dd))
  32. ## add key to to the row
  33. cbind(unique(d[,2:3]),dd)
  34. }))
  35.  
  36. Text2 Text3 Text11 Text12 Text41 Text42
  37. 1 Aba Abb Bob Robert Abc Abd
  38. 2 Abd Abe Fred <NA> Abf <NA>
  39. 3 Abg Abh Martin <NA> Abi <NA>
Add Comment
Please, Sign In to add comment