<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="generator" content="pandoc" /> <title>exercise solutions</title> <script src="site_libs/jquery-1.11.3/jquery.min.js"></script> <meta name="viewport" content="width=device-width, initial-scale=1" /> <link href="site_libs/bootstrap-3.3.5/css/cerulean.min.css" rel="stylesheet" /> <script src="site_libs/bootstrap-3.3.5/js/bootstrap.min.js"></script> <script src="site_libs/bootstrap-3.3.5/shim/html5shiv.min.js"></script> <script src="site_libs/bootstrap-3.3.5/shim/respond.min.js"></script> <script src="site_libs/jqueryui-1.11.4/jquery-ui.min.js"></script> <link href="site_libs/tocify-1.9.1/jquery.tocify.css" rel="stylesheet" /> <script src="site_libs/tocify-1.9.1/jquery.tocify.js"></script> <script src="site_libs/navigation-1.1/tabsets.js"></script> <link href="site_libs/font-awesome-5.0.13/css/fa-svg-with-js.css" rel="stylesheet" /> <script src="site_libs/font-awesome-5.0.13/js/fontawesome-all.min.js"></script> <script src="site_libs/font-awesome-5.0.13/js/fa-v4-shims.min.js"></script> <style type="text/css">code{white-space: pre;}</style> <style type="text/css"> div.sourceCode { overflow-x: auto; } table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode { margin: 0; padding: 0; vertical-align: baseline; border: none; } table.sourceCode { width: 100%; line-height: 100%; background-color: #f8f8f8; } td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; } td.sourceCode { padding-left: 5px; } pre, code { background-color: #f8f8f8; } code > span.kw { color: #204a87; font-weight: bold; } /* Keyword */ code > span.dt { color: #204a87; } /* DataType */ code > span.dv { color: #0000cf; } /* DecVal */ code > span.bn { color: #0000cf; } /* BaseN */ code > span.fl { color: #0000cf; } /* Float */ code > span.ch { color: #4e9a06; } /* Char */ code > span.st { color: #4e9a06; } /* String */ code > span.co { color: #8f5902; font-style: italic; } /* Comment */ code > span.ot { color: #8f5902; } /* Other */ code > span.al { color: #ef2929; } /* Alert */ code > span.fu { color: #000000; } /* Function */ code > span.er { color: #a40000; font-weight: bold; } /* Error */ code > span.wa { color: #8f5902; font-weight: bold; font-style: italic; } /* Warning */ code > span.cn { color: #000000; } /* Constant */ code > span.sc { color: #000000; } /* SpecialChar */ code > span.vs { color: #4e9a06; } /* VerbatimString */ code > span.ss { color: #4e9a06; } /* SpecialString */ code > span.im { } /* Import */ code > span.va { color: #000000; } /* Variable */ code > span.cf { color: #204a87; font-weight: bold; } /* ControlFlow */ code > span.op { color: #ce5c00; font-weight: bold; } /* Operator */ code > span.pp { color: #8f5902; font-style: italic; } /* Preprocessor */ code > span.ex { } /* Extension */ code > span.at { color: #c4a000; } /* Attribute */ code > span.do { color: #8f5902; font-weight: bold; font-style: italic; } /* Documentation */ code > span.an { color: #8f5902; font-weight: bold; font-style: italic; } /* Annotation */ code > span.cv { color: #8f5902; font-weight: bold; font-style: italic; } /* CommentVar */ code > span.in { color: #8f5902; font-weight: bold; font-style: italic; } /* Information */ </style> <style type="text/css"> pre:not([class]) { background-color: white; } </style> <style type="text/css"> h1 { font-size: 34px; } h1.title { font-size: 38px; } h2 { font-size: 30px; } h3 { font-size: 24px; } h4 { font-size: 18px; } h5 { font-size: 16px; } h6 { font-size: 12px; } .table th:not([align]) { text-align: left; } </style> </head> <body> <style type = "text/css"> .main-container { max-width: 940px; margin-left: auto; margin-right: auto; } code { color: inherit; background-color: rgba(0, 0, 0, 0.04); } img { max-width:100%; height: auto; } .tabbed-pane { padding-top: 12px; } .html-widget { margin-bottom: 20px; } button.code-folding-btn:focus { outline: none; } </style> <style type="text/css"> /* padding for bootstrap navbar */ body { padding-top: 51px; padding-bottom: 40px; } /* offset scroll position for anchor links (for fixed navbar) */ .section h1 { padding-top: 56px; margin-top: -56px; } .section h2 { padding-top: 56px; margin-top: -56px; } .section h3 { padding-top: 56px; margin-top: -56px; } .section h4 { padding-top: 56px; margin-top: -56px; } .section h5 { padding-top: 56px; margin-top: -56px; } .section h6 { padding-top: 56px; margin-top: -56px; } </style> <script> // manage active state of menu based on current page $(document).ready(function () { // active menu anchor href = window.location.pathname href = href.substr(href.lastIndexOf('/') + 1) if (href === "") href = "index.html"; var menuAnchor = $('a[href="' + href + '"]'); // mark it active menuAnchor.parent().addClass('active'); // if it's got a parent navbar menu mark it active as well menuAnchor.closest('li.dropdown').addClass('active'); }); </script> <div class="container-fluid main-container"> <!-- tabsets --> <script> $(document).ready(function () { window.buildTabsets("TOC"); }); </script> <!-- code folding --> <script> $(document).ready(function () { // move toc-ignore selectors from section div to header $('div.section.toc-ignore') .removeClass('toc-ignore') .children('h1,h2,h3,h4,h5').addClass('toc-ignore'); // establish options var options = { selectors: "h1,h2,h3", theme: "bootstrap3", context: '.toc-content', hashGenerator: function (text) { return text.replace(/[.\\/?&!#<>]/g, '').replace(/\s/g, '_').toLowerCase(); }, ignoreSelector: ".toc-ignore", scrollTo: 0 }; options.showAndHide = true; options.smoothScroll = true; // tocify var toc = $("#TOC").tocify(options).data("toc-tocify"); }); </script> <style type="text/css"> #TOC { margin: 25px 0px 20px 0px; } @media (max-width: 768px) { #TOC { position: relative; width: 100%; } } .toc-content { padding-left: 30px; padding-right: 40px; } div.main-container { max-width: 1200px; } div.tocify { width: 20%; max-width: 260px; max-height: 85%; } @media (min-width: 768px) and (max-width: 991px) { div.tocify { width: 25%; } } @media (max-width: 767px) { div.tocify { width: 100%; max-width: none; } } .tocify ul, .tocify li { line-height: 20px; } .tocify-subheader .tocify-item { font-size: 0.90em; padding-left: 25px; text-indent: 0; } .tocify .list-group-item { border-radius: 0px; } </style> <!-- setup 3col/9col grid for toc_float and main content --> <div class="row-fluid"> <div class="col-xs-12 col-sm-4 col-md-3"> <div id="TOC" class="tocify"> </div> </div> <div class="toc-content col-xs-12 col-sm-8 col-md-9"> <div class="navbar navbar-default navbar-fixed-top" role="navigation"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="index.html">intro-r-gis</a> </div> <div id="navbar" class="navbar-collapse collapse"> <ul class="nav navbar-nav"> <li> <a href="index.html">Home</a> </li> <li> <a href="setup.html">Setup</a> </li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"> <span class="fa fa-gear"></span> Handouts <span class="caret"></span> </a> <ul class="dropdown-menu" role="menu"> <li class="dropdown-header">Workshop Sections</li> <li> <a href="intro.html">Welcome</a> </li> <li> <a href="gis.html">Introduction to GIS</a> </li> <li> <a href="vector.html">Working with Vector Data</a> </li> <li> <a href="raster.html">Working with Raster Data</a> </li> <li class="divider"></li> <li> <a href="exercise_solutions.html">Exrecise solutions</a> </li> </ul> </li> </ul> <ul class="nav navbar-nav navbar-right"> <li> <a href="further_resources.html">Further Resources</a> </li> <li> <a href="https://github.com/annakrystalli/gis-workshop/archive/master.zip">Get Workshop Data</a> </li> <li> <a href="https://github.com/annakrystalli/intro-r-gis"> <span class="fa fa-github"></span> </a> </li> </ul> </div><!--/.nav-collapse --> </div><!--/.container --> </div><!--/.navbar --> <!-- Add a small amount of space between sections. --> <style type="text/css"> div.section { padding-top: 12px; } </style> <div class="fluid-row" id="header"> <h1 class="title toc-ignore">exercise solutions</h1> </div> <p><strong>Last updated:</strong> 2018-09-05</p> <strong>workflowr checks:</strong> <small>(Click a bullet for more information)</small> <ul> <li> <p><details> <summary> <strong style="color:blue;">✔</strong> <strong>R Markdown file:</strong> up-to-date </summary></p> <p>Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.</p> </details> </li> <li> <p><details> <summary> <strong style="color:blue;">✔</strong> <strong>Environment:</strong> empty </summary></p> <p>Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.</p> </details> </li> <li> <p><details> <summary> <strong style="color:blue;">✔</strong> <strong>Seed:</strong> <code>set.seed(20180820)</code> </summary></p> <p>The command <code>set.seed(20180820)</code> was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.</p> </details> </li> <li> <p><details> <summary> <strong style="color:blue;">✔</strong> <strong>Session information:</strong> recorded </summary></p> <p>Great job! Recording the operating system, R version, and package versions is critical for reproducibility.</p> </details> </li> <li> <p><details> <summary> <strong style="color:blue;">✔</strong> <strong>Repository version:</strong> <a href="https://github.com/annakrystalli/intro-r-gis/tree/513b4fb0743237f39de1f67d0bf0a880932f2601" target="_blank">513b4fb</a> </summary></p> Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility. The version displayed above was the version of the Git repository at the time these results were generated. <br><br> Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use <code>wflow_publish</code> or <code>wflow_git_commit</code>). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated: <pre><code> Ignored files: Ignored: .DS_Store Ignored: .Rhistory Ignored: .Rproj.user/ Ignored: analysis/.DS_Store Ignored: analysis/assets/ Ignored: data-raw/ Ignored: data/csv/ Ignored: data/raster/ Ignored: data/sf/ Ignored: docs/.DS_Store Untracked files: Untracked: .Rbuildignore Untracked: analysis/mapping.Rmd Unstaged changes: Modified: .gitignore Modified: analysis/_site.yml </code></pre> Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes. </details> </li> </ul> <details> <summary> <small><strong>Expand here to see past versions:</strong></small> </summary> <ul> <table style="border-collapse:separate; border-spacing:5px;"> <thead> <tr> <th style="text-align:left;"> File </th> <th style="text-align:left;"> Version </th> <th style="text-align:left;"> Author </th> <th style="text-align:left;"> Date </th> <th style="text-align:left;"> Message </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> html </td> <td style="text-align:left;"> <a href="https://cdn.rawgit.com/annakrystalli/intro-r-gis/ed98c23d29b24587c7a8fac69fe77f03c3df2666/docs/exercise_solutions.html" target="_blank">ed98c23</a> </td> <td style="text-align:left;"> annakrystalli </td> <td style="text-align:left;"> 2018-09-04 </td> <td style="text-align:left;"> Build site. </td> </tr> <tr> <td style="text-align:left;"> Rmd </td> <td style="text-align:left;"> <a href="https://github.com/annakrystalli/intro-r-gis/blob/33607af14ab2423a323b06a0ac0a5fa679aee131/analysis/exercise_solutions.Rmd" target="_blank">33607af</a> </td> <td style="text-align:left;"> annakrystalli </td> <td style="text-align:left;"> 2018-09-04 </td> <td style="text-align:left;"> workflowr::wflow_publish(“analysis/exercise_solutions.Rmd”) </td> </tr> <tr> <td style="text-align:left;"> html </td> <td style="text-align:left;"> <a href="https://cdn.rawgit.com/annakrystalli/intro-r-gis/0a20853aa681a9c8b3d11adfa35fa7fd23545c59/docs/exercise_solutions.html" target="_blank">0a20853</a> </td> <td style="text-align:left;"> annakrystalli </td> <td style="text-align:left;"> 2018-09-04 </td> <td style="text-align:left;"> Build site. </td> </tr> <tr> <td style="text-align:left;"> Rmd </td> <td style="text-align:left;"> <a href="https://github.com/annakrystalli/intro-r-gis/blob/6d820c1e05d54231e20681e5272369d4a7581f7a/analysis/exercise_solutions.Rmd" target="_blank">6d820c1</a> </td> <td style="text-align:left;"> annakrystalli </td> <td style="text-align:left;"> 2018-09-04 </td> <td style="text-align:left;"> workflowr::wflow_publish(c(“analysis/exercise_solutions.Rmd”)) </td> </tr> </tbody> </table> </ul> <p></details></p> <hr /> <div id="vector-spatial-data" class="section level2"> <h2>Vector spatial data</h2> <div id="add-a-nose" class="section level4"> <h4>1) add a nose!</h4> <p>Create a nose geometry, combine all the shapes into a single <code>sf</code> and then plot the face.</p> <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">nose <-<span class="st"> </span><span class="kw">st_linestring</span>(<span class="dt">x =</span> <span class="kw">matrix</span>(<span class="kw">c</span>(<span class="dv">1</span>, <span class="op">-</span><span class="dv">1</span>, <span class="dv">1</span>, <span class="op">-</span><span class="dv">2</span>), <span class="dt">ncol =</span> <span class="dv">2</span>, <span class="dt">byrow =</span> T)) sfc <-<span class="st"> </span><span class="kw">st_sfc</span>(points, line, nose) face <-<span class="st"> </span><span class="kw">st_sf</span>(<span class="kw">data.frame</span>(<span class="dt">shape =</span> <span class="kw">c</span>(<span class="st">"eyes"</span>, <span class="st">"mouth"</span>, <span class="st">"nose"</span>), <span class="dt">geom =</span> sfc)) <span class="kw">plot</span>(face)</code></pre></div> <p><img src="figure/exercise_solutions.Rmd/unnamed-chunk-2-1.png" width="672" style="display: block; margin: auto;" /></p> <details> <summary><em>Expand here to see past versions of unnamed-chunk-2-1.png:</em></summary> <table style="border-collapse:separate; border-spacing:5px;"> <thead> <tr> <th style="text-align:left;"> Version </th> <th style="text-align:left;"> Author </th> <th style="text-align:left;"> Date </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> <a href="https://github.com/annakrystalli/intro-r-gis/blob/0a20853aa681a9c8b3d11adfa35fa7fd23545c59/docs/figure/exercise_solutions.Rmd/unnamed-chunk-2-1.png" target="_blank">0a20853</a> </td> <td style="text-align:left;"> annakrystalli </td> <td style="text-align:left;"> 2018-09-04 </td> </tr> </tbody> </table> <p></details></p> </div> <div id="what-are-the-coordinates-for-the-10th-point-in-the-mexico-polygon" class="section level4"> <h4>2) What are the coordinates for the 10th point in the Mexico polygon?</h4> <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">mx_coords <-<span class="st"> </span>world <span class="op">%>%</span><span class="st"> </span><span class="kw">filter</span>(iso_a2 <span class="op">==</span><span class="st"> "MX"</span>) <span class="op">%>%</span><span class="st"> </span><span class="kw">st_coordinates</span>() mx_coords[<span class="dv">10</span>, <span class="kw">c</span>(<span class="st">"X"</span>, <span class="st">"Y"</span>)]</code></pre></div> <pre><code> X Y -106.50759 31.75452 </code></pre> </div> <div id="how-about-in-crs-mexico-itrf92-utm-zone-15n" class="section level4"> <h4>3) How about in CRS <a href="https://epsg.io/4488">Mexico ITRF92 / UTM zone 15N</a></h4> <p>(hint: use <code>st_transform</code> to change the projection first)</p> <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">mx_utm15 <-<span class="st"> </span>world <span class="op">%>%</span><span class="st"> </span> <span class="st"> </span><span class="kw">st_transform</span>(<span class="dt">crs =</span> <span class="dv">4488</span>) mx_coords <-<span class="st"> </span>mx_utm15 <span class="op">%>%</span> <span class="st"> </span><span class="kw">filter</span>(iso_a2 <span class="op">==</span><span class="st"> "MX"</span>) <span class="op">%>%</span><span class="st"> </span> <span class="st"> </span><span class="kw">st_coordinates</span>() mx_coords[<span class="dv">10</span>, <span class="kw">c</span>(<span class="st">"X"</span>, <span class="st">"Y"</span>)]</code></pre></div> <pre><code> X Y -784546.6 3593838.9 </code></pre> </div> <div id="are-these-coordinates-projected-or-not-can-you-tell-by-just-looking-at-the-crs-in-the-transformed-sf-object" class="section level4"> <h4>4) Are these coordinates projected or not? Can you tell by just looking at the CRS in the transformed <code>sf</code> object?</h4> <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">mx_utm15</code></pre></div> <pre><code>Simple feature collection with 177 features and 10 fields geometry type: MULTIPOLYGON dimension: XY bbox: xmin: -11779910 ymin: -19977280 xmax: 17183260 ymax: 19983850 epsg (SRID): 4488 proj4string: +proj=utm +zone=15 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs First 10 features: iso_a2 name_long continent region_un subregion 1 FJ Fiji Oceania Oceania Melanesia 2 TZ Tanzania Africa Africa Eastern Africa 3 EH Western Sahara Africa Africa Northern Africa 4 CA Canada North America Americas Northern America 5 US United States North America Americas Northern America 6 KZ Kazakhstan Asia Asia Central Asia 7 UZ Uzbekistan Asia Asia Central Asia 8 PG Papua New Guinea Oceania Oceania Melanesia 9 ID Indonesia Asia Asia South-Eastern Asia 10 AR Argentina South America Americas South America type area_km2 pop lifeExp gdpPercap 1 Sovereign country 19289.97 885806 69.96000 8222.254 2 Sovereign country 932745.79 52234869 64.16300 2402.099 3 Indeterminate 96270.60 NA NA NA 4 Sovereign country 10036042.98 35535348 81.95305 43079.143 5 Country 9510743.74 318622525 78.84146 51921.985 6 Sovereign country 2729810.51 17288285 71.62000 23587.338 7 Sovereign country 461410.26 30757700 71.03900 5370.866 8 Sovereign country 464520.07 7755785 65.23000 3709.082 9 Sovereign country 1819251.33 255131116 68.85600 10003.089 10 Sovereign country 2784468.59 42981515 76.25200 18797.548 geom 1 MULTIPOLYGON (((-11776327 -... 2 MULTIPOLYGON (((7508185 -19... 3 MULTIPOLYGON (((9294103 882... 4 MULTIPOLYGON (((-1664512 58... 5 MULTIPOLYGON (((-1664512 58... 6 MULTIPOLYGON (((473784.4 14... 7 MULTIPOLYGON (((3108708 149... 8 MULTIPOLYGON (((-6664974 -1... 9 MULTIPOLYGON (((-6664974 -1... 10 MULTIPOLYGON (((2134436 -61...</code></pre> <p>We’ve already talked about UTM being projected CRSs but there is also a hint in the <code>proj4string</code>, in particular <code>+units=m</code> indicating that the units are linear (m).</p> <p>We can also extract the units from an <code>sf</code>s crs using function <code>sf::st_crs()</code> and accessing the units</p> <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">st_crs</span>(mx_utm15)<span class="op">$</span>units</code></pre></div> <pre><code>[1] "m"</code></pre> </div> </div> <div id="raster-spatial-data" class="section level2"> <h2>Raster spatial data</h2> <div id="create-and-plot-a-new-rasterlayer-of-rough-mean-temperature-in-degrees-c" class="section level4"> <h4>1) Create and plot a new <code>rasterLayer</code> of rough mean temperature in degrees C</h4> <p>(rough because it would be much better to use more data at higher temporal resolution, eg at least monthly, not extremes).</p> <p>We can do this using a simple mean calculation:</p> <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">rough_mean <-<span class="st"> </span>((full_stack[[<span class="st">"mx.bio_5"</span>]] <span class="op">+</span><span class="st"> </span>full_stack[[<span class="st">"mx.bio_6"</span>]])<span class="op">/</span><span class="dv">2</span>)<span class="op">/</span><span class="dv">10</span></code></pre></div> <p>But we can even use r functions, in this case <code>mean()</code></p> <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">rough_mean <-<span class="st"> </span><span class="kw">mean</span>(full_stack[[<span class="st">"mx.bio_5"</span>]], full_stack[[<span class="st">"mx.bio_6"</span>]])<span class="op">/</span><span class="dv">10</span></code></pre></div> <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">rough_mean</code></pre></div> <pre><code>class : RasterLayer dimensions : 563, 811, 456593 (nrow, ncol, ncell) resolution : 0.008333333, 0.008333333 (x, y) extent : -101.85, -95.09167, 16.94167, 21.63333 (xmin, xmax, ymin, ymax) coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 data source : /Users/Anna/Documents/workflows/workshops/intro-r-gis/data/raster/rough_mean.tif names : rough_mean values : -1.45, 29.6 (min, max)</code></pre> <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">levelplot</span>(rough_mean, <span class="dt">margin =</span> F)</code></pre></div> <p><img src="figure/exercise_solutions.Rmd/unnamed-chunk-11-1.png" width="672" style="display: block; margin: auto;" /></p> <details> <summary><em>Expand here to see past versions of unnamed-chunk-11-1.png:</em></summary> <table style="border-collapse:separate; border-spacing:5px;"> <thead> <tr> <th style="text-align:left;"> Version </th> <th style="text-align:left;"> Author </th> <th style="text-align:left;"> Date </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> <a href="https://github.com/annakrystalli/intro-r-gis/blob/0a20853aa681a9c8b3d11adfa35fa7fd23545c59/docs/figure/exercise_solutions.Rmd/unnamed-chunk-11-1.png" target="_blank">0a20853</a> </td> <td style="text-align:left;"> annakrystalli </td> <td style="text-align:left;"> 2018-09-04 </td> </tr> </tbody> </table> <p></details></p> </div> <div id="calculate-mean-precipitation-seasonality-for-the-extraction-bounding-box-area.-what-is-the-value" class="section level4"> <h4>2) Calculate mean precipitation seasonality for the <strong>extraction bounding box area</strong>. What is the value?</h4> <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">mean_prec_seasonality <-<span class="st"> </span><span class="kw">extract</span>(env_stack[[<span class="st">"prec_seasonality"</span>]], <span class="kw">as_Spatial</span>(extract_bbox), <span class="dt">fun =</span> mean, <span class="dt">na.rm =</span> T) mean_prec_seasonality</code></pre></div> <pre><code> [,1] [1,] 87.78957</code></pre> </div> <div id="add-a-column-indicating-whether-data-points-are-greater-than-true-or-less-than-false-extraction-area-mean-precipitation-seasonality." class="section level4"> <h4>3) Add a column indicating whether data points are greater than (<code>TRUE</code>) or less than (<code>FALSE</code>) extraction area mean precipitation seasonality.</h4> <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">mol_env_sf <-<span class="st"> </span>mol_env_sf <span class="op">%>%</span><span class="st"> </span> <span class="st"> </span><span class="kw">mutate</span>(<span class="dt">greater_mean_ps =</span> prec_seasonality <span class="op">></span><span class="st"> </span><span class="kw">as.vector</span>(mean_prec_seasonality)) mol_env_sf <span class="op">%>%</span><span class="st"> </span><span class="kw">select</span>(locality, greater_mean_ps)</code></pre></div> <pre><code>Simple feature collection with 15 features and 2 fields geometry type: POINT dimension: XY bbox: xmin: -99.84806 ymin: 18.94194 xmax: -97.09056 ymax: 19.63083 epsg (SRID): 4326 proj4string: +proj=longlat +datum=WGS84 +no_defs # A tibble: 15 x 3 locality greater_mean_ps geometry <chr> <lgl> <POINT [°]> 1 Nevado de Toluca FALSE (-99.84806 19.19361) 2 Texcalyacac TRUE (-99.5 19.12056) 3 Desierto de los Leones TRUE (-99.30056 19.26667) 4 Ajusco TRUE (-99.3 19.18278) 5 Calpan TRUE (-98.59167 19.13139) 6 Atzompa TRUE (-98.55972 19.18056) 7 Llano Grande FALSE (-98.72056 19.33889) 8 Rio Frio FALSE (-98.69472 19.36611) 9 Nanacamilpa FALSE (-98.59611 19.48028) 10 MalincheS FALSE (-98.02194 19.18722) 11 MalincheW FALSE (-98.095 19.25778) 12 MalincheE FALSE (-97.975 19.23) 13 Texmalaquilla FALSE (-97.29 18.94194) 14 Xometla FALSE (-97.19056 18.975) 15 Vigas FALSE (-97.09056 19.63083)</code></pre> </div> </div> <div id="session-information" class="section level2"> <h2>Session information</h2> <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">sessionInfo</span>()</code></pre></div> <pre><code>R version 3.4.4 (2018-03-15) Platform: x86_64-apple-darwin15.6.0 (64-bit) Running under: macOS High Sierra 10.13.3 Matrix products: default BLAS: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.dylib LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib locale: [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] bindrcpp_0.2.2 spData_0.2.9.3 ggplot2_3.0.0 [4] dplyr_0.7.6 sf_0.6-3 rasterVis_0.45 [7] latticeExtra_0.6-28 RColorBrewer_1.1-2 lattice_0.20-35 [10] raster_2.6-7 sp_1.2-5 loaded via a namespace (and not attached): [1] zoo_1.8-3 tidyselect_0.2.4 purrr_0.2.5 [4] colorspace_1.3-2 htmltools_0.3.6 viridisLite_0.3.0 [7] yaml_2.1.19 utf8_1.1.3 rlang_0.2.1 [10] R.oo_1.21.0 e1071_1.6-8 hexbin_1.27.1 [13] pillar_1.2.1 glue_1.2.0.9000 withr_2.1.2 [16] DBI_1.0.0 R.utils_2.6.0 bindr_0.1.1 [19] plyr_1.8.4 stringr_1.3.1 munsell_0.5.0 [22] gtable_0.2.0 workflowr_1.0.1 R.methodsS3_1.7.1 [25] evaluate_0.11 knitr_1.20 parallel_3.4.4 [28] class_7.3-14 Rcpp_0.12.18 backports_1.1.2 [31] scales_1.0.0 classInt_0.1-24 digest_0.6.15 [34] stringi_1.2.4 grid_3.4.4 rprojroot_1.3-2 [37] cli_1.0.0 rgdal_1.3-4 here_0.1 [40] tools_3.4.4 magrittr_1.5 lazyeval_0.2.1 [43] tibble_1.4.2 crayon_1.3.4 whisker_0.3-2 [46] pkgconfig_2.0.2 assertthat_0.2.0 rmarkdown_1.10 [49] R6_2.2.2 units_0.6-0 git2r_0.21.0 [52] compiler_3.4.4 </code></pre> </div> <!-- Adjust MathJax settings so that all math formulae are shown using TeX fonts only; see http://docs.mathjax.org/en/latest/configuration.html. This will make the presentation more consistent at the cost of the webpage sometimes taking slightly longer to load. Note that this only works because the footer is added to webpages before the MathJax javascript. --> <script type="text/x-mathjax-config"> MathJax.Hub.Config({ "HTML-CSS": { availableFonts: ["TeX"] } }); </script> <hr> <p> This reproducible <a href="http://rmarkdown.rstudio.com">R Markdown</a> analysis was created with <a href="https://github.com/jdblischak/workflowr">workflowr</a> 1.0.1 </p> <hr> </div> </div> </div> <script> // add bootstrap table styles to pandoc tables function bootstrapStylePandocTables() { $('tr.header').parent('thead').parent('table').addClass('table table-condensed'); } $(document).ready(function () { bootstrapStylePandocTables(); }); </script> <!-- dynamically load mathjax for compatibility with self-contained --> <script> (function () { var script = document.createElement("script"); script.type = "text/javascript"; script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"; document.getElementsByTagName("head")[0].appendChild(script); })(); </script> </body> </html>