title: merge two data frames based on matching rows of multiple columns
body: <p>Below is the summary and structure of the two data sets I tried to merge <code>claimants</code> and <code>unemp</code>, they can me found here <a href="https://github.com/blsingh/Board-Q-A/blob/master/claims.csv" rel="nofollow noreferrer">claims.csv</a> and <a href="https://github.com/blsingh/Board-Q-A/blob/master/unemp.csv" rel="nofollow noreferrer">unemp.csv</a></p>
  
  <pre><code> &gt; tbl_df(claimants)
  # A tibble: 6,960 × 5
         X       County  Month  Year Claimants
     &lt;int&gt;       &lt;fctr&gt; &lt;fctr&gt; &lt;int&gt;     &lt;int&gt;
  1      1      ALAMEDA    Jan  2007     13034
  2      2       ALPINE    Jan  2007        12
  3      3       AMADOR    Jan  2007       487
  4      4        BUTTE    Jan  2007      3496
  5      5    CALAVERAS    Jan  2007       644
  6      6       COLUSA    Jan  2007      1244
  7      7 CONTRA COSTA    Jan  2007      8475
  8      8    DEL NORTE    Jan  2007       328
  9      9    EL DORADO    Jan  2007      2120
  10    10       FRESNO    Jan  2007     19974
  # ... with 6,950 more rows
  
  
  &gt; tbl_df(unemp)
  # A tibble: 6,960 × 7
      County  Year Month laborforce emplab unemp unemprate
  *    &lt;chr&gt; &lt;int&gt; &lt;chr&gt;      &lt;int&gt;  &lt;int&gt; &lt;int&gt;     &lt;dbl&gt;
  1  Alameda  2007   Jan     743100 708300 34800       4.7
  2  Alameda  2007   Feb     744800 711000 33800       4.5
  3  Alameda  2007   Mar     746600 713200 33300       4.5
  4  Alameda  2007   Apr     738200 705800 32400       4.4
  5  Alameda  2007   May     739100 707300 31800       4.3
  6  Alameda  2007   Jun     744900 709100 35800       4.8
  7  Alameda  2007   Jul     749600 710900 38700       5.2
  8  Alameda  2007   Aug     746700 709600 37000       5.0
  9  Alameda  2007   Sep     748200 712100 36000       4.8
  10 Alameda  2007   Oct     749000 713000 36100       4.8
  # ... with 6,950 more rows
  </code></pre>
  
  <p>I thought first I should change all the <code>factor</code> columns to <code>character</code> columns.</p>
  
  <pre><code>unemp[sapply(unemp, is.factor)] &lt;- lapply(unemp[sapply(unemp, is.factor)], as.character)
  
  claimants[sapply(claimants, is.factor)] &lt;- lapply(claimants[sapply(claimants, is.factor)], as.character)
  
  m &lt;-merge(unemp, claimants, by = c("County", "Month", "Year"))
  dim(m)
  [1]  0 10
  </code></pre>
  
  <p>In the output of <code>dim(m)</code>, 0 rows are in the resulting dataframe. All the 6960 rows should match each other uniquely.  </p>
  
  <p>To verify that the two data frames have unique combination of the the 3 columns 'County', 'Month', and 'Year' I reorder and rearrange these columns within the dataframes as below:</p>
  
  <pre><code>a &lt;- claimants[ order(claimants[,"County"], claimants[,"Month"], claimants[,"Year"]), ]
  
  b &lt;- unemp[ order(unemp[,"County"], unemp[,"Month"], unemp[,"Year"]), ]
  
  b[2:4] &lt;- b[c(2,4,3)]
  a[2:4] %in% b[2:4]
  [1] TRUE TRUE TRUE
  </code></pre>
  
  <p>This last output confirms that all 'County', 'Month', and 'Year' columns match each other in these two dataframes.  </p>
  
  <p>I have tried looking into the documentation for <code>merge</code> and could not gather where do I go wrong, I have also tried the <code>inner_join</code> function from <code>dplyr</code>:</p>
  
  <pre><code>&gt; m &lt;- inner_join(unemp[2:8], claimants[2:5])
  Joining, by = c("County", "Year", "Month")
  &gt; dim(m)
  [1] 0 8 
  </code></pre>
  
  <p>I am missing something and don't know what, would appreciate the help with understanding this, I know I should not have to rearrange the rows by the three columns to run <code>merge</code> R should identify the matching rows and merge the non-matching columns.</p>