title: Using uniroot function in r with data from data frame to solve Euler-Lotka equation
body: <p>I'd like to solve an equation for a variable for each line of a given csv file.
  You may know the equation as the Euler-Lotka equation.
  That is what I have so far:</p>
  
  <pre><code># seed is needed for reproducible results (otherwise random numbers will      never be the same!)
  set.seed(42)
  
  # using the Euler-Lotka equation
  # l = survival rate until age x
  # m = amount of offspring at age x
  # x = age of reproduction
  # r = population growth rate
  y &lt;- function(r, l1, l2, l3, m1, m2, m3, x1, x2, x3, z){((l1*m1*exp(-r*x1)) + (l2*m2*exp(-r*x2)) + (l3*m3*exp(-r*x3))) - z}
  
  # iterate through each line calculating r and writing it into the respective field
  for (i in 1:length(neos_data$jar_no)){
  
  # declare the variables from table (this does not work!!)
  l1 &lt;- neos_data$surv_rate_clutch1[i]
  l2 &lt;- neos_data$surv_rate_clutch2[i]
  l3 &lt;- neos_data$surv_rate_clutch3[i]
  m1 &lt;- neos_data$indiv_sum_1_clutch[i]
  m2 &lt;- neos_data$indiv_sum_2_clutch[i]
  m3 &lt;- neos_data$indiv_sum_3_clutch[i]
  x1 &lt;- neos_data$age_clutch_1[i]
  x2 &lt;- neos_data$age_clutch_2[i]
  x3 &lt;- neos_data$age_clutch_3[i]
  
  # this works, while these numbers are the same as in the data frame
  l1 &lt;- 0.9333333
  l2 &lt;- 0.9333333
  l3 &lt;- 0.9333333
  m1 &lt;- 3.4
  m2 &lt;- 0
  m3 &lt;- 0
  x1 &lt;- 9
  x2 &lt;- 13
  x3 &lt;- 16
  
    ## uniroot finds a 0 value, so offset function, thats why -z in the upper formula
    r &lt;- uniroot(y, l1=l1, l2=l2, l3=l3, m1=m1, m2=m2, m3=m3, x1=x1, x2=x2, x3=x3, z = 1, interval = c(-1, 1))[1] #writing only the result of r into variable
  
    # write r into table
    neos_data$pop_gr[i] &lt;- r
  
  }
  </code></pre>
  
  <p>As I already commented, uniroot works fine with manual input of values. But when try to load a value from my data frame it gives the error "values of f() have the same sign".</p>
  
  <p>I do understand the meaning of the error itself, but why does it work with the values I insert manually and not with the same values from the data frame (and yes, I have checked the data types).</p>
  
  <p>Would be glad for any help, as what I've seen so far was not helpful in my case :)</p>
  
  <p>EDIT: 
  To clearify: I'd like to get a value of r for which the equation becomes 0. This works with the given code very fine as far as I insert the values of the variables as a number. But when I try to pass the value from my data frame, it fails even if the same values are passed.</p>