title: Input column name as variable in a function
body: <p>I'm trying to write a function that I can use across multiple dataframes which accepts column names as input. The objective is to identify whether an event happened (if it was the earliest) and then code the results into a binary 0 and 1. This is what I've come up with so far:</p>
  <pre><code>event &lt;- function(x){
    analysis$event &lt;- 0
    analysis$event[analysis$earliest == analysis$x] &lt;- 1
  }
  </code></pre>
  <p>However, when I try it with say <code>test &lt;- event(death_date)</code> it returns just a value of 1. What went wrong and how can I fix it? Thanks!</p>