title: Calculate variable depending on column specification
body: <p>I have a data set containing eye tracking data looking similar to this dummy.df</p>
  
  <pre><code>dummy.df &lt;- data.frame(GY = sample(300:600, 500, replace = T), 
                     target.position = sample(c("up", "down"), 500, replace = T),
                     trial.number = rep(1:10, each = 50))
  toptargetpos_px &lt;- 550
  bottomtargetpos_px &lt;- 350 
  </code></pre>
  
  <p>GY is the position data of the eye on the Y-axis. 
  toptargetpos and bottomtargetpos represent a horizontal line on the Y axis that the eye has to cross. 
  I would like to mutate an extra column which specifies per target.position if the horizontal line is crossed.</p>
  
  <p>So what is can do is:</p>
  
  <pre><code>dummy.df %&gt;%
    mutate(on.target = GY &gt;= toptargetpos_px)
  </code></pre>
  
  <p>This gives TRUE if GY is indeed above toptargetpos_px. However, i want the script to take into account what the target.position is (up or down), so it takes the corresponding horizontal line (toptargetpos_px or bottomtarget_px)</p>
  
  <p>Which would look something like this:</p>
  
  <pre><code>dummy.df %&gt;%
    mutate(on.target = GY[target.position == "up"] &gt;= toptargetpos_px) | 
                       GY[target.position == "down" &lt;= bottomtargetpos_px]
  </code></pre>
  
  <p>However, this is not working. What can i do to make it work ? I can ofcourse make 2 columns, but this is not ideal. </p>