title: Conditionally mapping values from one data frame to another one R
body: <p>I have two dataframes: </p>
  
  <pre><code>&gt; SubObj
  
  sNumber runningTrialNo  wordTar      SubObj_ind
  
  1       34              nerd         3
  1       32              hooligan     1
  1       7               villager     3
  2       32              oak          2
  2       8               deer         2
  3       8               mammal       3
  
  &gt; df
  
  sNumber runningTrialNo  wordTar
  
  1       34              nerd
  1       34              nerd
  1       34              nerd
  1       32              hooligan
  1       32              hooligan
  1       7               villager
  2       32              oak
  2       32              oak
  2       8               deer
  3       8               mammal
  3       8               mammal
  </code></pre>
  
  <p>I want to map values from SubObj$SubObj_ind into df$SubObj, so all the values would be in accordance with sNumber (subject number) and runningTrialNo (trial number). It should look smth like this: </p>
  
  <pre><code>&gt; df
  
  sNumber runningTrialNo  wordTar    SubObj_ind
  
  1       34              nerd       3
  1       34              nerd       3
  1       34              nerd       3
  1       32              hooligan   1
  1       32              hooligan   1
  1       7               villager   3
  2       32              oak        2
  2       32              oak        2
  2       8               deer       2
  3       8               mammal     3
  3       8               mammal     3
  </code></pre>
  
  <p>I wrote the code that hypothetically should do the work but it doesn't map over trial and subject number:</p>
  
  <pre><code> df$SubObj_indO &lt;- array(0, nrow(df))
   for(i in 1:nrow(SubObj)) {
      index &lt;- df$runningTrialNo == SubObj[i,"runningTrialNo"] &amp;
         df$sNumber == SubObj[i,"sNumber"]
      df$SubObj_ind[index] &lt;- SubObj[index, "SubObj_ind"]
   }
  </code></pre>
  
  <p>What is wrong in this peace of the code? </p>