Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. dt1 <- data.table(ids = c(1, 2, 5), col1 = c("A", "B", "F"), col2 = c("B", "F", "G"))
  2. dt2 <- data.table(ids = c(2, 1, 6, 5), col1 = c("B", "A", "K", "L"), col2 = c("F", "G", "M", "G"))
  3.  
  4. > dt1
  5. ids col1 col2
  6. 1: 1 A B
  7. 2: 2 B F
  8. 3: 5 F G
  9.  
  10. > dt2
  11. ids col1 col2
  12. 1: 2 B F
  13. 2: 1 A G
  14. 3: 6 K M
  15. 4: 5 L G
  16.  
  17. joint_dt <- merge(dt1, dt2, by = "ids", suffixes = c("", "_old"))
  18. comp_res <- mapply(function(x, y) sum(x == y), joint_dt[, 2:ncol(dt1)], joint_dt[, (ncol(dt1) + 1):ncol(joint_dt)])
  19.  
  20. > comp_res
  21. col1 col2
  22. 2 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement