Trying to create a pi estimator in R
<p>This is a homework problem. I am brand new to R just FYI
This is the problem:
R does have a built-in constant <code>pi</code>. Here we will use random numbers to estimate the value of 
π. Create a function <code>approx.pi()</code> that takes a parameter <code>N</code>. Inside this function, code the 
following steps: </p>

<ul>
<li>(1) set <code>j</code> equal to 0. </li>
<li>(2) start a for loop with counter <code>i</code> that repeats <code>N</code> times. </li>
<li>(3) Inside the for loop, generate two random uniform numbers <code>x</code> and <code>y</code> between -1 and +1 
using <code>runif()</code>. </li>
<li>(4) If <code>x^2 + y^2 &lt; 1</code> then add one to <code>j</code>. </li>
<li>(5) End the <code>for</code> loop. </li>
<li>(6) Return the estimate of π which is <code>4×j/N</code></li>
</ul>

<p>and this is the code I have:</p>

<pre><code>approx.pi &lt;- function(N) {
    j &lt;- 0
    for (i in N) {
        x &lt;- runif(1,-1,1)
        y &lt;- runif(1,-1,1)
        if (x^2+y^2&lt; 1)  {
            j=j+1
        }
    }
    return(4*j/N)
}
approx.pi(N=5)
</code></pre>

<p>I am getting some number values returned but they are no where near pi can anyone help? Thank you.</p>