title: Match from a key and return unique ID in R
body: <p>The task: I webscraped a large data set that includes a variable (data$author) I need to clean. It's partly organized by job title, partly organized by name. I need this naming convention standardized for analysis by the correct job title held by the associated person's name. So, in my below example, Jim is the Prez, Bob is the CEO, etc. A further complication is that people move around in jobs over time, so the name-job link is associated by year. In short, I want to create a new variable in the dataframe with a standardized job title.</p>
  
  <p>Here's my thinking: create a matching function to check each entry against the master key, and return the correct job title (by associated name+date) to a new vector.</p>
  
  <pre><code>jobs &lt;- c("Prez", "CEO", "VP", "VP", "Director", "Assistant", "Secretary", "Intern")
  names &lt;- c("Susan", "Bob", "Susan", "Jim", "Gail", "Emily", "Dan", "Anne")
  year &lt;- c("86", "85-86", "85", "85-86", "85-86", "85-86", "85-86", "85-86")
  
  key &lt;- cbind(jobs, names, year)
  
  DocID &lt;- c(1:20)
  author &lt;- sample(c(jobs,names), 20, replace=T)
  data &lt;- cbind(DocID, author, year_data)
  
  data$cleaned &lt;- Magic.Clean.Function(data$author)
  </code></pre>
  
  <p>Hoping to end up with a 'data$cleaned' vector listing just the corrected job titles.</p>
  
  <p>EDIT: Sorry if this is a little messy, I'm trying to recreate a simplified version of my actual DF. Thanks for the help!</p>