0

I would like to merge two dataframes based on two conditions, one of which examines the percent match across two rows. In the following example, I would like to force a perfect match across the variable x and a match across y based on if there is any unique letter match:

f1 <- data.frame(x = c(1,2,3), y = c("aa", "ff", "cd"), z = c(4,5,6))
f2 <- data.frame(x = c(1,2,3), y = c("aa", "bb", "cc"), z = c(7,9,10))

To produce:

1 1  aa   4  aa   7
3 3  cd   6  cc  10

Ultimately, I would like to figure out how to include a function in the merge that looks through conditions. Thanks.

coding_heart
  • 1,245
  • 3
  • 25
  • 46
  • What happens if `f2 <- data.frame(x = c(1,2,3, 4), y = c("aa", "bb", "cc", "dd"), z = c(7,9,10, 11))`? Are these 1:many matches? – MrFlick May 16 '14 at 19:00
  • In this case, the match would not go to the fourth row since they don't match on x. – coding_heart May 16 '14 at 19:52
  • But the "cd" value in `f1` would match to both row 3 and 4 in `f2`. – MrFlick May 16 '14 at 19:56
  • Indeed, but the variable "x" would not match on those (it is 3 in f1 and 4 in f2). – coding_heart May 16 '14 at 20:02
  • Ok, fine, what about `f2 <- data.frame(x = c(1,2,3,3), y = c("aa", "bb", "cc", "dd"), z = c(7,9,10, 11))` The point is, what if there is a partial match to more than one element on the second column. – MrFlick May 16 '14 at 20:05
  • Ahh, I see (sorry about). For a partial match to more than one element, it would be great to generate two matches (i.e. one for row 4 and one for row 4). – coding_heart May 16 '14 at 20:12

0 Answers0