Skip to content

Commit

Permalink
Built site for gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Quarto GHA Workflow Runner committed Mar 31, 2023
1 parent bf72ca9 commit 7d07fb8
Show file tree
Hide file tree
Showing 36 changed files with 140 additions and 116 deletions.
2 changes: 1 addition & 1 deletion .nojekyll
Original file line number Diff line number Diff line change
@@ -1 +1 @@
e9f26fd9
0840b77b
40 changes: 26 additions & 14 deletions data-frames.html

Large diffs are not rendered by default.

83 changes: 42 additions & 41 deletions data-visualization.html

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions data-wrangling.html
Original file line number Diff line number Diff line change
Expand Up @@ -1046,13 +1046,11 @@ <h3 id="suggested-readings" class="unnumbered anchored">Suggested Readings</h3>
<p>Of course, in this particular case the <code><a href="https://dplyr.tidyverse.org/reference/if_else.html">if_else()</a></code> function isn’t even needed because the condition returns <code>TRUE</code> and <code>FALSE</code> values. However, if you wanted to extend this example to determine all four seasons, you could use a series of nested <code><a href="https://dplyr.tidyverse.org/reference/if_else.html">if_else()</a></code> functions:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb59"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va">df</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html">%&gt;%</a></span></span>
<span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span><span class="op">(</span>season <span class="op">=</span></span>
<span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/if_else.html">if_else</a></span><span class="op">(</span></span>
<span> <span class="va">incident_month</span> <span class="op"><a href="https://rdrr.io/r/base/match.html">%in%</a></span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">3</span>, <span class="fl">4</span>, <span class="fl">5</span><span class="op">)</span>, <span class="st">'Spring'</span>,</span>
<span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/if_else.html">if_else</a></span><span class="op">(</span></span>
<span> <span class="va">incident_month</span> <span class="op"><a href="https://rdrr.io/r/base/match.html">%in%</a></span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">6</span>, <span class="fl">7</span>, <span class="fl">8</span><span class="op">)</span>, <span class="st">'Summer'</span>,</span>
<span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/if_else.html">if_else</a></span><span class="op">(</span></span>
<span> <span class="va">incident_month</span> <span class="op"><a href="https://rdrr.io/r/base/match.html">%in%</a></span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">9</span>, <span class="fl">10</span>, <span class="fl">11</span><span class="op">)</span>, <span class="st">'Fall'</span>, <span class="st">'Winter'</span><span class="op">)</span><span class="op">)</span><span class="op">)</span><span class="op">)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span><span class="op">(</span>season <span class="op">=</span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/if_else.html">if_else</a></span><span class="op">(</span></span>
<span> <span class="va">incident_month</span> <span class="op"><a href="https://rdrr.io/r/base/match.html">%in%</a></span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">3</span>, <span class="fl">4</span>, <span class="fl">5</span><span class="op">)</span>, <span class="st">'Spring'</span>, <span class="fu"><a href="https://dplyr.tidyverse.org/reference/if_else.html">if_else</a></span><span class="op">(</span></span>
<span> <span class="va">incident_month</span> <span class="op"><a href="https://rdrr.io/r/base/match.html">%in%</a></span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">6</span>, <span class="fl">7</span>, <span class="fl">8</span><span class="op">)</span>, <span class="st">'Summer'</span>, <span class="fu"><a href="https://dplyr.tidyverse.org/reference/if_else.html">if_else</a></span><span class="op">(</span></span>
<span> <span class="va">incident_month</span> <span class="op"><a href="https://rdrr.io/r/base/match.html">%in%</a></span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">9</span>, <span class="fl">10</span>, <span class="fl">11</span><span class="op">)</span>, <span class="st">'Fall'</span>, <span class="st">'Winter'</span><span class="op">)</span></span>
<span> <span class="op">)</span><span class="op">)</span><span class="op">)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Note: The Base R version of this function is <code><a href="https://rdrr.io/r/base/ifelse.html">ifelse()</a></code>, but I recommend using the <code>dplyr</code> version, <code><a href="https://dplyr.tidyverse.org/reference/if_else.html">if_else()</a></code>, as it is a <a href="https://stackoverflow.com/questions/50646133/dplyr-if-else-vs-base-r-ifelse">stricter function</a>.</p>
</section><section id="page-sources" class="level2 unnumbered"><h2 class="unnumbered anchored" data-anchor-id="page-sources">Page sources</h2>
Expand Down
6 changes: 5 additions & 1 deletion extensions.html
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,11 @@ <h1 class="title"><span id="sec-extensions" class="quarto-section-identifier d-n

</header>

<p>Coming soon!</p>
<p>In this section I’ll show how to do a few specific things in R that build on all the tools we’ve seen so far. This section is a constant work in progress, so come back later for more concepts. For now, it includes two sub-sections:</p>
<ul>
<li><a href="./monte-carlo-methods.html">Monte Carlo Methods</a></li>
<li><a href="./python-in-r.html">Using Python in R</a></li>
</ul>



Expand Down
Binary file added figs/ggplot-bars-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figs/ggplot-bars-fill-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figs/ggplot-bars-summary-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figs/ggplot-bars2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figs/ggplot-blank-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figs/ggplot-scatter-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figs/ggplot-scatter-blue-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figs/ggplot-scatter-color-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figs/ggplot-scatter-economist-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figs/ggplot-scatter-labs-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figs/ggplot-scatter-minimal-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figs/hist-basic-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figs/hist-basic-pretty-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figs/integration-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figs/integration-box-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figs/monte-carlo-pie-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figs/msleep-bars-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figs/msleep-scatter-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figs/msleep-scatter1-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figs/msleep-scatter2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figs/scatter-basic-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figs/scatter-basic-pretty-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/unnamed-chunk-2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/unnamed-chunk-3-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/unnamed-chunk-33-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/unnamed-chunk-34-1.png
4 changes: 2 additions & 2 deletions functions-packages.html
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ <h3 id="suggested-readings" class="unnumbered anchored">Suggested Readings</h3>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/r/base/date.html">date</a></span><span class="op">(</span><span class="op">)</span> <span class="co"># Returns the current date and time</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>#&gt; [1] "Fri Mar 31 11:42:18 2023"</code></pre>
<pre><code>#&gt; [1] "Fri Mar 31 12:13:17 2023"</code></pre>
</div>
</div>
<p>(the date above is the date this page was last built)</p>
Expand Down Expand Up @@ -710,7 +710,7 @@ <h3 id="suggested-readings" class="unnumbered anchored">Suggested Readings</h3>
<p><img src="images/turtle_setpos.png" class="img-fluid" width="456"></p>
</section><section id="turtle-loops" class="level3" data-number="3.4.2"><h3 data-number="3.4.2" class="anchored" data-anchor-id="turtle-loops">
<span class="header-section-number">3.4.2</span> Turtle loops</h3>
<p>Simple enough, right? But what if I want my turtle to draw a more complicated shape? Let’s say I want her to draw a hexagon. There are six sides to the hexagon, so the most natural way to write code for this is to write a <code>for</code> loop that loops over the sides (don’t worry if this doesn’t make sense yet - we’ll get to <a href="L5-loops.html">loops in week 5</a>!). At each iteration within the loop, I’ll have the turtle walk forwards, and then turn 60 degrees to the left. Here’s what happens:</p>
<p>Simple enough, right? But what if I want my turtle to draw a more complicated shape? Let’s say I want her to draw a hexagon. There are six sides to the hexagon, so the most natural way to write code for this is to write a <code>for</code> loop that loops over the sides (if this doesn’t make sense yet, go read ahead to the chapter on <a href="./iteration.html">iteration</a>!). At each iteration within the loop, I’ll have the turtle walk forwards, and then turn 60 degrees to the left. Here’s what happens:</p>
<!-- ```{r, fig.show='animate', interval=0.05, cache=TRUE, message=FALSE} -->
<!-- ffmpeg is a pain, so manually sticking video in -->
<div class="cell" data-layout-align="center">
Expand Down
48 changes: 28 additions & 20 deletions monte-carlo-methods.html
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ <h1 class="title"><span id="sec-monte-carlo-methods" class="quarto-section-ident
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><img src="figs/unnamed-chunk-2-1.png" class="img-fluid figure-img" width="576"></p>
<figure class="figure"><p><img src="figs/integration-1.png" class="img-fluid figure-img" width="576"></p>
</figure>
</div>
</div>
Expand All @@ -361,7 +361,7 @@ <h1 class="title"><span id="sec-monte-carlo-methods" class="quarto-section-ident
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><img src="figs/unnamed-chunk-3-1.png" class="img-fluid figure-img" width="576"></p>
<figure class="figure"><p><img src="figs/integration-box-1.png" class="img-fluid figure-img" width="576"></p>
</figure>
</div>
</div>
Expand Down Expand Up @@ -430,20 +430,20 @@ <h1 class="title"><span id="sec-monte-carlo-methods" class="quarto-section-ident
<p><strong>Let’s write the code!</strong></p>
<p>First, generate lots of random points in a square. For this example, we’ll use a square with side length of 1 centered at <code>(x, y) = (0, 0)</code>, so we need to draw random points between <code>x = (-0.5, 0.5)</code> and <code>y = (-0.5, 0.5)</code>:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va">numTrials</span> <span class="op">&lt;-</span> <span class="fl">1000</span></span>
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va">numTrials</span> <span class="op">&lt;-</span> <span class="fl">10000</span></span>
<span><span class="va">points</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/data.frame.html">data.frame</a></span><span class="op">(</span></span>
<span> x <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/stats/Uniform.html">runif</a></span><span class="op">(</span><span class="va">numTrials</span>, <span class="op">-</span><span class="fl">0.5</span>, <span class="fl">0.5</span><span class="op">)</span>,</span>
<span> y <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/stats/Uniform.html">runif</a></span><span class="op">(</span><span class="va">numTrials</span>, <span class="op">-</span><span class="fl">0.5</span>, <span class="fl">0.5</span><span class="op">)</span></span>
<span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/utils/head.html">head</a></span><span class="op">(</span><span class="va">points</span><span class="op">)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>#&gt; x y
#&gt; 1 0.229506132 0.139484990
#&gt; 2 -0.007594905 -0.002580851
#&gt; 3 0.109975740 -0.202333914
#&gt; 4 -0.219826613 0.163189993
#&gt; 5 -0.011846287 0.301705838
#&gt; 6 -0.175026551 -0.030729181</code></pre>
<pre><code>#&gt; x y
#&gt; 1 0.229506132 -0.08053840
#&gt; 2 -0.007594905 0.04727206
#&gt; 3 0.109975740 0.18632628
#&gt; 4 -0.219826613 0.35889460
#&gt; 5 -0.011846287 -0.09219395
#&gt; 6 -0.175026551 -0.23989452</code></pre>
</div>
</div>
<p>For this example, we’re putting the points in a data frame to make it easier to work with. Now that we have random x and y points, let’s compute the radius to each point (the distance from <code>(x, y) = (0, 0)</code>) so we can determine which points fall inside the circle (which has a radius of 0.5):</p>
Expand All @@ -458,30 +458,38 @@ <h1 class="title"><span id="sec-monte-carlo-methods" class="quarto-section-ident
</div>
<p>Just to make sure we correctly labeled the points, let’s plot them, coloring them based on the <code>pointInCircle</code> variable we just created:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://ggplot2.tidyverse.org">ggplot2</a></span><span class="op">)</span></span>
<span></span>
<span><span class="fu"><a href="https://ggplot2.tidyverse.org/reference/ggplot.html">ggplot</a></span><span class="op">(</span><span class="va">points</span><span class="op">)</span> <span class="op">+</span></span>
<span> <span class="fu"><a href="https://ggplot2.tidyverse.org/reference/geom_point.html">geom_point</a></span><span class="op">(</span></span>
<span> <span class="fu"><a href="https://ggplot2.tidyverse.org/reference/aes.html">aes</a></span><span class="op">(</span>x <span class="op">=</span> <span class="va">x</span>, y <span class="op">=</span> <span class="va">y</span>, color <span class="op">=</span> <span class="va">pointInCircle</span><span class="op">)</span>,</span>
<span> size <span class="op">=</span> <span class="fl">0.5</span></span>
<span> <span class="op">)</span> <span class="op">+</span></span>
<span> <span class="fu"><a href="https://ggplot2.tidyverse.org/reference/ggtheme.html">theme_minimal</a></span><span class="op">(</span><span class="op">)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure"><p><img src="figs/unnamed-chunk-9-1.png" class="img-fluid figure-img" width="576"></p>
<figure class="figure"><p><img src="figs/monte-carlo-pie-1.png" class="img-fluid figure-img" width="576"></p>
</figure>
</div>
</div>
</div>
<p>Looks like we correctly labeled the points! Now we have everything we need to estimate <span class="math inline">\(\pi\)</span>!</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va">ratio</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/sum.html">sum</a></span><span class="op">(</span><span class="va">points</span><span class="op">$</span><span class="va">pointInCircle</span><span class="op">)</span> <span class="op">/</span> <span class="fu"><a href="https://rdrr.io/r/base/nrow.html">nrow</a></span><span class="op">(</span><span class="va">points</span><span class="op">)</span></span>
<div class="sourceCode" id="cb8"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va">ratio</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/sum.html">sum</a></span><span class="op">(</span><span class="va">points</span><span class="op">$</span><span class="va">pointInCircle</span><span class="op">)</span> <span class="op">/</span> <span class="fu"><a href="https://rdrr.io/r/base/nrow.html">nrow</a></span><span class="op">(</span><span class="va">points</span><span class="op">)</span></span>
<span><span class="va">piApprox</span> <span class="op">&lt;-</span> <span class="fl">4</span> <span class="op">*</span> <span class="va">ratio</span></span>
<span><span class="va">piApprox</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>#&gt; [1] 3.084</code></pre>
<pre><code>#&gt; [1] 3.1256</code></pre>
</div>
</div>
<div class="cell" data-layout-align="center">

</div>
<p>So our estimate error is: <code>3.1415 -</code> <code>3.084</code> <code>=</code> <code>-0.0575927</code>.</p>
<p>That’s an error of just 1.83 % - not bad for only 1,000 points!</p>
<p>So our estimate error is: <code>3.1415 -</code> <code>3.1256</code> <code>=</code> <code>-0.0159927</code>.</p>
<p>That’s an error of just 0.51 % - not bad for only 1,000 points!</p>
<p>To get an even better estimate of <span class="math inline">\(\pi\)</span>, we can increase N. Let’s see what we get with 100,000 trials:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb9"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va">numTrials</span> <span class="op">&lt;-</span> <span class="fl">100000</span></span>
<div class="sourceCode" id="cb10"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va">numTrials</span> <span class="op">&lt;-</span> <span class="fl">100000</span></span>
<span></span>
<span><span class="va">points</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/data.frame.html">data.frame</a></span><span class="op">(</span></span>
<span> x <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/stats/Uniform.html">runif</a></span><span class="op">(</span><span class="va">numTrials</span>, <span class="op">-</span><span class="fl">0.5</span>, <span class="fl">0.5</span><span class="op">)</span>,</span>
Expand All @@ -495,17 +503,17 @@ <h1 class="title"><span id="sec-monte-carlo-methods" class="quarto-section-ident
<span><span class="va">piApprox</span> <span class="op">&lt;-</span> <span class="fl">4</span> <span class="op">*</span> <span class="va">ratio</span></span>
<span><span class="va">piApprox</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>#&gt; [1] 3.13844</code></pre>
<pre><code>#&gt; [1] 3.13876</code></pre>
</div>
<div class="sourceCode" id="cb11"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="co"># Compute error:</span></span>
<div class="sourceCode" id="cb12"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="co"># Compute error:</span></span>
<span><span class="va">error</span> <span class="op">&lt;-</span> <span class="va">piApprox</span> <span class="op">-</span> <span class="va">pi</span></span>
<span><span class="va">percentError</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/Round.html">round</a></span><span class="op">(</span><span class="fl">100</span><span class="op">*</span><span class="fu"><a href="https://rdrr.io/r/base/MathFun.html">abs</a></span><span class="op">(</span><span class="va">error</span> <span class="op">/</span> <span class="va">pi</span><span class="op">)</span>, <span class="fl">2</span><span class="op">)</span></span>
<span><span class="va">percentError</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>#&gt; [1] 0.1</code></pre>
<pre><code>#&gt; [1] 0.09</code></pre>
</div>
</div>
<p>By increasing the number of trials from 1,000 to 100,000, we improved our estimate error from 1.83 % to 0.1 %!</p>
<p>By increasing the number of trials from 1,000 to 100,000, we improved our estimate error from 0.51 % to 0.09 %!</p>
</section><section id="page-sources" class="level2 unnumbered"><h2 class="unnumbered anchored" data-anchor-id="page-sources">Page sources</h2>
<p>Some content on this page has been modified from other courses, including:</p>
<ul>
Expand Down
Loading

0 comments on commit 7d07fb8

Please sign in to comment.