title: Add values to a column of dataframe based on the common values with a column of another dataframe
body: <p>I have the 2 datasets below:</p>
  
  <pre><code>stud&lt;-c("MARK","DGHN","BHKJ")
  mark&lt;-c(4,6,7)
  d1&lt;-data.frame(stud,mark)
  
  stud2&lt;-c("MARK","DGHN","BHKJ","dfgd","fg")
  mark2&lt;-""
  d2&lt;-data.frame(stud2,mark2)
  </code></pre>
  
  <p>I want to pass to the <code>mark2</code> of <code>d2</code> the values of <code>mark</code> of <code>d1</code> for the students that exist in both <code>stud</code> and <code>stud2</code>. The rest of the names of the <code>stud2</code> should remain as they are but their respective <code>mark2</code> values should be <code>NAs</code>.I tried:</p>
  
  <pre><code>d2$stud2 &lt;- factor(d2$stud2, levels=levels(d1$stud))
  d2$mark2 &lt;- ifelse(d2$stud2 == d1$stud, d1$mark, NA)
  </code></pre>
  
  <p>but not all of the <code>stud2</code> values appear. Is there another way without having to mess with the fact that they do not have the same count of factors?</p>