title: Match dataframe rows according to two variables (Indexing)
body: <p>I am essentially trying to get disorganized data into long form for linear modeling.</p>
  
  <p>I have 2 data.frames "rec" and "book"</p>
  
  <p>Each row in "book" needs to be pasted onto the end of several of the rows of "rec" according to two variables in the row: "MRN" and "COURSE" which match.</p>
  
  <p>I have tried the following and variations thereon to no avail:</p>
  
  <pre><code>i=1
  newlist=list()
  colnames(newlist)=colnames(book)
  for ( i in 1:dim(rec)[1]) {
      mrn=as.numeric(as.vector(rec$MRN[i]));
      course=as.character(rec$COURSE[i]);
  get.vector&lt;-as.vector(((as.numeric(as.vector(book$MRN))==mrn) &amp; (as.character(book$COURSE)==course)))
  newlist[i]&lt;-book[get.vector,] 
  i=i+1;
  }
  </code></pre>
  
  <p>If anyone has any suggestions on </p>
  
  <p>1)getting this to work
  2) making it more elegant (or perhaps just less clumsy)</p>
  
  <p>If I have been unclear in any way I beg your pardons.</p>
  
  <p>I do understand I haven't combined any data above, I think if I can generate a long-format data.frame I can combine them all on my own</p>