title: Merging Two Datasets on Matched Column in R
body: <p>I'm an R beginner and I'm trying to merge two datasets and having some trouble with losing data. I might be totally off base with what I'm doing.</p>
  <p>The first dataset is the Dewey Decimal System and the data looks like this
  <a href="https://i.stack.imgur.com/N66i5.png" rel="nofollow noreferrer">image of 10 rows of data from this set</a></p>
  <p>I've named this dataset DDC</p>
  <p>The next dataset is a list of books ordered during a particular time period.
  <a href="https://i.stack.imgur.com/iSwYu.png" rel="nofollow noreferrer">image of 10 rows of the book ordering dataset</a>
  I've named this dataset DOA</p>
  <p>I'm unsure how to include the data not in an image
  (Can also provide the .csvs if needed)</p>
  <p>I would like to merge the sets based on the first three digits of the call number.</p>
  <p>To achieve this I've created a new variable in both sets called  Call_Category2 that takes the first three digits of the call number value to be matched.</p>
  <p><code>DDC$Call_Category2 = str_pad(DDC$Call_Category, width = 3, side = &quot;left&quot;, pad = &quot;0&quot;)</code></p>
  <p>This dataset is just over 1000 rows. It is also padded because the 000 to 099 Dewey Decimal Classifications were dropping their leading 0s</p>
  <pre><code>DOA_data = transform(DOA_data, Call_Category2 = substr(Call_Category, 1,3))
  </code></pre>
  <p>This dataset is about 24000 rows.</p>
  <p>I merge the sets and create a new set called DOA_Call</p>
  <pre><code>DOA_Call = merge(DDC, DOA_data, all.x = TRUE)
  </code></pre>
  <p>When I head the data the merge seems to be working properly but 10,000 rows do not get the DOA_Call data added. They just stay in their original state. This is about 40% of my total dataset so it is pretty substantial. My first instinct was that it was only putting DDC rows in once but that would mean I would be missing 23,000 rows which I'm not.</p>
  <p>Am I doing something wrong with the merge or could it be an issue with the data not being clean enough?</p>
  <p>Let me know if more information is needed!</p>
  <p>I don't necessarily need code, pointers on what direction to troubleshoot in would be very helpful!</p>