title: using variable column names in dplyr (do)
body: <p>I have the following example data</p>
  
  <pre><code>d.1 = data.frame(id=c(1,1,2,3,3), date=c(2001,2002,2001,2001,2003), measure=c(1:5))
  d.2 = data.frame(id=c(1,2,2,3,3), date=c(2001,2002,2003,2002,2008), measure=c(1:5))
  d = merge(d.1,d.2, all=T, by="id")
  </code></pre>
  
  <p><code>d.1</code> and <code>d.2</code> are two kinds of measurements and I need one of each measurements per <code>id</code>. The measurements should be as close to each other as possible. I can do that with <code>dplyr</code> by</p>
  
  <pre><code>require(dplyr)
  d = d %&gt;%
      group_by(id) %&gt;%
      do(.[which.min(abs(.$date.x-.$date.y)),])
  </code></pre>
  
  <p>The question is how i can use <code>dplyr</code> if the names of the date columns are saved in a variable like <code>name.x="date.x"</code> and <code>name.y="date.y"</code> because i can't use</p>
  
  <pre><code>...
  do(.[which.min(abs(.[, name.x]-.[, name.y])),])
  ....
  </code></pre>
  
  <p>I tried to find anaother solution using <code>eval</code>, <code>as.symbol</code> ans stuff like that but i couldn't figure out a solution... </p>