<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/computing-wind-average-in-an-area-using-rwind/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://allthiswasfield.blogspot.com/2017/12/computing-wind-average-in-area-using.html"> long time ago...</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>

<p></p>
<div>Hi all!</div>
<div></div>
<div>A researcher asked me last week about how to compute wind average for an area using rWind. I wrote a simple function to do this using dplyr library (following the advice of my friend <a rel="nofollow" href="https://www.researchgate.net/profile/Javier_Fajardo4" target="_blank">Javier Fajardo</a>). The function will be added to rWind package as soon as possible. Meanwhile, you can test the results… enjoy!</div>
<div>
<div><a rel="nofollow" href="https://i1.wp.com/3.bp.blogspot.com/-50lNtHnLZlc/WibBFK07yGI/AAAAAAAAAM0/l8FEUGROa0g_n-IFLy-a6hpGlUVt7JCZQCEwYBhgL/s1600/Rplot04.png?ssl=1" target="_blank"><img border="0" data-original-height="831" src="https://i0.wp.com/3.bp.blogspot.com/-50lNtHnLZlc/WibBFK07yGI/AAAAAAAAAM0/l8FEUGROa0g_n-IFLy-a6hpGlUVt7JCZQCEwYBhgL/s320/Rplot04.png?resize=450%2C831&ssl=1" data-recalc-dims="1" data-original-width="450"></a></div>
<p></div>
<div></div>
<div></div>
<pre><code> # First, charge the new function  <br> library(dplyr)  <br> wind.region &lt;- function (X){   <br>  X[,3] &lt;- X[,3] %% 360   <br>  X[X[,3]>=180,3] &lt;- X[X[,3]>=180,3] - 360   <br>  avg&lt;-summarise_all(X[,-1], .funs = mean)   <br>  wind_region &lt;- cbind(X[1,1],avg)   <br>  return(wind_region)   <br> }   <br></code></pre>
<p>Once you have charged the function, let’s do some example</p>
<pre><code> # Get some wind data and convert it into a raster to be plotted later  <br> library(rWind)  <br> library(raster)  <br> wind_data&lt;-wind.dl(2015,2,12,0,-10,5,35,45)  <br> wind_fitted_data &lt;- wind.fit(wind_data)  <br> r_speed &lt;- wind2raster(wind_fitted_data, type=&quot;speed&quot;)  <br></code></pre>
<p>Now, you can use the new function to obtain wind average in the study area:</p>
<p></p>
<pre><code> myMean &lt;- wind.region(wind_data)  <br> myMean  <br></code></pre>
<div><a rel="nofollow" href="https://i0.wp.com/3.bp.blogspot.com/-jdcSN2tI4PE/Wia6rSYIEaI/AAAAAAAAAMc/a9QSK7bCsPosjxcEII2Yaxl2PkofUadmwCLcBGAs/s1600/myMean.png?ssl=1" target="_blank"><img border="0" data-original-height="47" src="https://i2.wp.com/3.bp.blogspot.com/-jdcSN2tI4PE/Wia6rSYIEaI/AAAAAAAAAMc/a9QSK7bCsPosjxcEII2Yaxl2PkofUadmwCLcBGAs/s400/myMean.png?resize=450%2C47&ssl=1" data-recalc-dims="1" data-original-width="450"></a></div>
<p></p>
<pre><code> # Now, you can use wind.fit to get wind speed and direction.  <br> myMean_fitted &lt;- wind.fit(myMean)  <br> myMean_fitted  <br></code></pre>
<div><a rel="nofollow" href="https://i2.wp.com/2.bp.blogspot.com/-H2aU3GNAFhs/Wia7F6dZR2I/AAAAAAAAAMk/m_osDA2PEtM1jzPHGw5Xg7654QZXHUNbACEwYBhgL/s1600/myMean2.png?ssl=1" target="_blank"><img border="0" data-original-height="50" src="https://i2.wp.com/2.bp.blogspot.com/-H2aU3GNAFhs/Wia7F6dZR2I/AAAAAAAAAMk/m_osDA2PEtM1jzPHGw5Xg7654QZXHUNbACEwYBhgL/s1600/myMean2.png?resize=207%2C50&ssl=1" data-recalc-dims="1" data-original-width="207"></a></div>
<p></p>
<pre><code> # Finally, let's plot the results!  <br> library(rworldmap)  <br> library(shape)  <br> plot(r_speed)  <br> lines(getMap(resolution = &quot;low&quot;), lwd=4)   <br> alpha &lt;- arrowDir(myMean_fitted)  <br> Arrowhead(myMean_fitted$lon, myMean_fitted$lat, angle=alpha,   <br>      arr.length = 2, arr.type=&quot;curved&quot;)  <br> text(myMean_fitted$lon+1, myMean_fitted$lat+1,   <br>    paste(round(myMean_fitted$speed,2), &quot;m/s&quot;), cex = 2)  <br></code></pre>
<p></p>
<div><a rel="nofollow" href="https://i2.wp.com/2.bp.blogspot.com/-50lNtHnLZlc/WibBFK07yGI/AAAAAAAAAMw/wFg5V4pDGVEE7lJHIR73BdO60JGqphpEgCLcBGAs/s1600/Rplot04.png?ssl=1" target="_blank"><img border="0" data-original-height="831" src="https://i0.wp.com/2.bp.blogspot.com/-50lNtHnLZlc/WibBFK07yGI/AAAAAAAAAMw/wFg5V4pDGVEE7lJHIR73BdO60JGqphpEgCLcBGAs/s400/Rplot04.png?resize=450%2C831&ssl=1" data-recalc-dims="1" data-original-width="450"></a></div>
<p></p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://allthiswasfield.blogspot.com/2017/12/computing-wind-average-in-area-using.html"> long time ago...</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/m62DuNg7ado" height="1"></a></div>