I'd like to merge two dataset based on Permno columns. But one of the datasets has 5 Permno columns instead of 1. The following table is a simplified example of what the 2nd dataset looks like:
execid | exec-fname | Permno | Permno1 | Permno2 | Permno3 | Permno4 |
---|---|---|---|---|---|---|
124 | William | 17743 | ||||
125 | Warren | 83443 | 17778 | |||
897 | Chris | 18092 | ||||
393 | James | 75294 | 81774 |
This is an reproducible snippet of my data:
structure(list(permno = structure(c(17743, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 18092
), label = "Historical CRSP PERMNO Link to COMPUSTAT Record", format.stata = "%12.0g"),
permno1 = structure(c(NA, 83443, 83443, 83443, 83443, 83443,
83443, 83443, 83443, 83443, 17778, 17778, 17778, 17778, 17778,
17778, 17778, 17778, 17778, 17778, NA), label = "1 permno", format.stata = "%12.0g"),
permno2 = structure(c(NA, 17778, 17778, 17778, 17778, 17778,
17778, 17778, 17778, 17778, 83443, 83443, 83443, 83443, 83443,
83443, 83443, 83443, 83443, 83443, NA), label = "2 permno", format.stata = "%12.0g"),
permno3 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "3 permno", format.stata = "%12.0g"),
permno4 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "4 permno", format.stata = "%12.0g"),
execid = structure(c(124, 125, 125, 125, 125, 125, 125, 125,
125, 125, 125, 125, 125, 125, 125, 125, 125, 125, 125, 125,
133), label = "(firstnm) execid", format.stata = "%10.0g"),
exec_lname = structure(c("Berkley", "Buffett", "Buffett",
"Buffett", "Buffett", "Buffett", "Buffett", "Buffett", "Buffett",
"Buffett", "Buffett", "Buffett", "Buffett", "Buffett", "Buffett",
"Buffett", "Buffett", "Buffett", "Buffett", "Buffett", "Miller"
), label = "(firstnm) exec_lname", format.stata = "%20s"),
exec_fname = structure(c("William", "Warren", "Warren", "Warren",
"Warren", "Warren", "Warren", "Warren", "Warren", "Warren",
"Warren", "Warren", "Warren", "Warren", "Warren", "Warren",
"Warren", "Warren", "Warren", "Warren", "Dane"), label = "(firstnm) exec_fname", format.stata = "%26s")), row.names = c(NA,
-21L), class = c("tbl_df", "tbl", "data.frame"))
The 1st data set only has 1 Permno. How can I merge the two datasets based on the Permno and check every column of the 2nd data set for a match?