title: R: Find X-value corresponding to specific Y-value on graph
body: <p>I study a continuous variable, measured every ten minutes for 2 hours.
  I wonder what at what time the variable has doubled and tripled.</p>
  
  <pre><code>Example data:
  # The time variable
  time &lt;- seq(from = 0, to = 120, by=10)
  # The measured variable
  value &lt;- c(5, 5.5, 7.8, 8.3, 9.5, 10.9, 11.5, 12, 13, 14, 12.5, 11.1, 9)
  # Put together
  df &lt;- data.frame(time, value)
  # Plotted
  ggplot(df, aes(time, value)) + geom_line()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/cb1FW.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cb1FW.jpg" alt="enter image description here"></a></p>
  
  <pre><code># At what time point (what X value) does Y equal (for example) 10?
  
  # I've tried (according to previous suggestions on this site (but they turned out to be not reliable, and heavily dependent upon the "interval" specified.
  
  f1 &lt;- approxfun(df$time, df$value)
  optimize(function(t0) abs(f1(t0) - 10), interval = c(0, 120))[[1]]
  </code></pre>
  
  <p>Does anyone know of any other function that can find the X value without dependence upon an interval. The reason for me asking again, is that changing the interval slightly (but keeping it within the true value) changes the result...</p>
  
  <p>Thanks for any advice</p>