Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. heads
  2. row1
  3. row2
  4. row3
  5. row4
  6. row5
  7.  
  8. heads
  9. row3
  10. row5
  11.  
  12. heads
  13. row1
  14. row2
  15. row4
  16.  
  17. library(dplyr)
  18. anti_join(df, df1, by='heads')
  19.  
  20. library(data.table)
  21. setkey(setDT(df), heads)[!df1]
  22. # heads
  23. # 1: row1
  24. # 2: row2
  25. # 3: row4
  26.  
  27. setDT(df)[!df1, on = "heads"]
  28.  
  29. fsetdiff(df, df1, all = TRUE)
  30.  
  31. df[!df$heads %in% df1$heads,]
  32.  
  33. df2 <- data.frame(heads = setdiff(df$heads, df1$heads))
  34.  
  35. library(plyr)
  36. negate_match_df <- function (x, y, on = NULL)
  37. {
  38. if (is.null(on)) {
  39. on <- intersect(names(x), names(y))
  40. message("Matching on: ", paste(on, collapse = ", "))
  41. }
  42. keys <- join.keys(x, y, on)
  43. x[!keys$x %in% keys$y, , drop = FALSE]
  44. }
  45.  
  46. df <- read.table(text ="heads
  47. row1
  48. row2
  49. row3
  50. row4
  51. row5",header=TRUE)
  52.  
  53. df1 <- read.table(text ="heads
  54. row3
  55. row5",header=TRUE)
  56.  
  57. negate_match_df(df,df1)
  58.  
  59. library(sqldf)
  60. sql <- "SELECT t1.heads
  61. FROM df t1 LEFT JOIN df1 t2
  62. ON t1.heads = t2.heads
  63. WHERE t2.heads IS NULL"
  64. df2 <- sqldf(sql)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement