0

I m trying to merge 2 files with postal code in R.

One file has financial info by state and postal codes (file a) and the other file has postal code, country, activities, and dates(file b). Some of the postal code in the first file a are not present in the second file b.

So I m trying to merge all the postal codes of file b with that of file a without losing any information on my file a.

My code is:

merge(a, b, by="posta code", all.x=TRUE)
Sandy
  • 1,100
  • 10
  • 18
memile
  • 9
  • 3
  • 2
    Clearly a duplicate (flagged). For future reference, please share a reproducible example. In this case, paste the output of `dput(head(a))` and `dput(head(b))` – JDG Oct 31 '19 at 10:29
  • And, what's the question ? ^^' – Bram Oct 31 '19 at 10:30

1 Answers1

0

If you like SQL, you could try following code:

library(sqldf)
combined = sqldf("SELECT a.*, country, activity, date
                  FROM a JOIN b
                  using(`postal code`)")
Sandy
  • 1,100
  • 10
  • 18