3

Let's say I have a list of suburb names, crime rate and their council names on a separate table.

Tables Picture

I know that left_join(table1, table2, by=Suburb) will return the table with newly added rows due to the multiple matches for council. The problem is that suburbs 3 and 4 overlap into two councils.

Is there a way to only get the left join to only return the first match only rather than creating new rows to facilitate for the extra ones?

In addition, on Table 2, is there a function to only keep the first row of each suburb and remove the second/third/fourth instances where the second/third/fourth council overlapping occurs?

JamCon
  • 2,313
  • 2
  • 25
  • 34
user7438322
  • 109
  • 1
  • 2
  • 6

1 Answers1

3

You can do this using the plyr package and the join() function. The equivalent to left_join(table1, table2, by=Suburb) but only using the first Suburb match from table2 would be: join(table1, table2, by=Suburb, type="left", match="first"). I'm not sure what the equivalent is in the dplyr package, though I would love to know myself.

Rebecca412
  • 49
  • 3