I have two data frames in R:
My goal is two find the common rows between two data frames according to two columns and select them in the first one.
For example, I have the below data frames:
c<- data.frame(A = c(4,6,7), B = c(5,9,8),C = c("T","T","F"))
d<- data.frame(A = c(6,7,3),B = c(9,8,3))
And I want the result to be:
# A B C
# 6 9 T
# 7 8 F
>Solution :
You can use the following code:
c<- data.frame(A = c(4,6,7), B = c(5,9,8),C = c("T","T","F"))
d<- data.frame(A = c(6,7,3),B = c(9,8,3),C = c("T","F","F"))
merge(c, d, by= c("A", "B", "C"))
Output:
A B C
1 6 9 T
2 7 8 F