title: Harmonic series sum function in R
body: <p>I am trying to write a function which takes a positive real number and keeps adding terms of the harmonic series until the total sum exceeds the initial argument. 
  I need my function to display the total number of terms of the series that were added.</p>
  
  <p>Here's my code so far:</p>
  
  <pre><code>harmonic&lt;-function(n){
    x&lt;-c(0,1)
    while (length(x) &lt; n) {
      position &lt;- length(x)
      new &lt;- 1/(x[position] + x[position-1])
      x &lt;- c(x,new)
    }
    return(x)
  }
  </code></pre>
  
  <p>I apologise for the errors in my code, unfortunately I have been working with R only for a month and this is the first time that I am using the while loop and I couldn't find any useful information around.</p>
  
  <p>Thank you, I'd really appreciate your help.</p>