I have two data sets (data frames). I would like to find match values between these data sets based on each column names.
intput1 <- structure(list(A = c(1L, 0L, 1L, 0L), B = c(2L, 2L, 1L, 1L),
C = c(3L, 1L, 1L, 3L)), .Names = c("A", "B", "C"), class = "data.frame",
row.names = c("1", "2", "3", "4"))
# A B C
#1 1 2 3
#2 0 2 1
#3 1 1 1
#4 0 1 3
input2 <- structure(list(A = c(1L, 3L, 1L, 0L), B = c(1L, 2L, 0L, 1L),
C = c(2L, 2L, 1L, 2L)), .Names = c("A", "B", "C"), class = "data.frame",
row.names = c("1", "2", "3", "4"))
# A B C
#1 1 1 2
#2 3 2 2
#3 1 0 1
#4 0 1 2
Expected output:
# colnames.1 colnames.2 match
#1 A A 3
#2 A B 1
#3 A C 1
#4 B A 1
#5 B B 2
#6 B C 2
#7 C A 1
#8 C B 0
#9 C C 1
where the final column is the number of matches.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…