Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dt1 <- data.table(ids = c(1, 2, 5), col1 = c("A", "B", "F"), col2 = c("B", "F", "G"))
- dt2 <- data.table(ids = c(2, 1, 6, 5), col1 = c("B", "A", "K", "L"), col2 = c("F", "G", "M", "G"))
- > dt1
- ids col1 col2
- 1: 1 A B
- 2: 2 B F
- 3: 5 F G
- > dt2
- ids col1 col2
- 1: 2 B F
- 2: 1 A G
- 3: 6 K M
- 4: 5 L G
- joint_dt <- merge(dt1, dt2, by = "ids", suffixes = c("", "_old"))
- comp_res <- mapply(function(x, y) sum(x == y), joint_dt[, 2:ncol(dt1)], joint_dt[, (ncol(dt1) + 1):ncol(joint_dt)])
- > comp_res
- col1 col2
- 2 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement