0

For a project, I have 2 data frames that need to be merged on Investor Name.

Df1 contains information on firms and 5 investors names (different columns; Investor 1, Investor 2, ..., Investor 5) Df2 contains information on specific investors.

I want to check if the investor name in df2 is among one of the five investor's names of a firm in df1, and then merge that information. In other words, I want to add investor info of df2 to each row in df1.

Example: Firm X in DF1 has Investor A, B, C, D, and E (5 columns with names) DF2 contains information on investor B. Thus, I want to merge on the 'name' of Investor B to add the investor information to the row of Firm X.

How should I create a merge like this?

I tried this, but the number of columns needs to be equal in this statement

df_merge <- merge(df1, df2, by.x=c("Investor1", "Investor2", "Investor3", "Investor4", "Investor5"), by.y=c("Investor.Name"))
MLavoie
  • 9,671
  • 41
  • 36
  • 56
  • please edit your question so that others can reproduce it (by adding some minimal example data). see here for guidance: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Benjamin Schwetz Apr 09 '21 at 11:16
  • also it sounds like you might want to pivot your data, i.e. make gather investors in one column https://tidyr.tidyverse.org/reference/pivot_longer.html. – Benjamin Schwetz Apr 09 '21 at 11:18

0 Answers0