1

I have 2 data frames (a1 and a2)

a1
A   B   C   D
1   A   6   8
2   D   7   3 #**
3   X   3   3

a2
A   B   C   D
4   D   2   3 #**
5   Z   3   5
6   X   3   4


a1 <- data.frame(
  A = 1:3,
  B = c("A", "D", "X"),
  C = c(6, 7, 3),
  D = c(8, 3, 3)
)
a2 <- data.frame(
  A = 4:6,
  B = c("D", "Z", "X"),
  C = c(2, 3, 3),
  D = c(3, 5, 4)
)

I want to get the tuples (a1$A,a2$A) for the rows which have the same values in colums B and D

In this example, I would get (2,4) because they have the same values in colums B and D, respectively D and 3

1
  • Do a1 and a2 have the same number of rows? Commented Aug 31, 2011 at 10:53

1 Answer 1

3

Use merge to merge the data frames.

merged <- merge(a1, a2, c("B", "D"))
subset(merged, select = c(A.x, A.y))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.