title: Using a pair from a dataframe to transform another dataframe
body: <p>I have two dataframes, which data I have to tidy. One that has the data to transform:</p>
  
  <pre><code>df &lt;- data.frame(age=c("(0,5]", "(5,10]", "(10,15]", "(15,20]", "(20,25]", "(25,30]"),
             locNPlaces=c("AS, loc2", "aS, loc1", "AD, loc1",
                          "af, loc3", "loc4, AS", "AS, loc3"))
  </code></pre>
  
  <p>And another with the id and names of the values</p>
  
  <pre><code>idPlaces &lt;- data.frame(id=c(1, 2, 3, 4, 5, 6),
             places=c("AS", "AD", "AF", "BA", "BC", "BD"))
  </code></pre>
  
  <p>I need to create a new column with the id of the places on df. It would look like this:</p>
  
  <pre><code>      age locNPlaces placesId
  1   (0,5]   AS, loc2        1
  2  (5,10]   aS, loc1        1
  3 (10,15]   AD, loc1        2
  4 (15,20]   AF, loc3        3
  5 (20,25]   AS, loc4        1
  6 (25,30]   AS, loc3        1
  </code></pre>
  
  <p>I wouldn't like to have to do it like this</p>
  
  <pre><code>df %&gt;% mutate(placesId=
                       if(grepl("AS", locNPlaces, ignore.case=T)) 1,
                   if(grepl("AD", locNPlaces, ignore.case=T)) 2,
                   if(grepl("AF", locNPlaces, ignore.case=T)) 3)
  </code></pre>
  
  <p>since there are several of these cases and the don't have the same pairs, it would require me to redo this for each new set of pairs. Is there an easy way to use the pairs on a dataframe to create a new column?</p>