<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/learn-parallel-programming-in-r-with-these-exercises-for-foreach/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://blog.revolutionanalytics.com/2017/07/foreach-exercises.html"> Revolutions</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div>
<p>The <a rel="nofollow" href="https://mran.microsoft.com/package/foreach/" target="_blank">foreach package</a> provides a simple looping construct for R: the <code>foreach</code> function, which you may be familiar with from other languages like Javascript or C#. It's basically a function-based version of a <code>&quot;for&quot;</code> loop. But what makes foreach useful isn't iteration: it's the way it makes it easy to run those iterations in parallel, and save time on multi-CPU and distributed systems.</p>
<p>If you want to get familiar with the <code>foreach</code> function, <a rel="nofollow" href="https://docs.microsoft.com/en-us/r-server/r/how-to-revoscaler-distributed-computing-foreach" target="_blank">Parallelizing Loops</a> at Microsoft Docs will introduce you to foreach oops (and the companion concept, <em>iterators</em>), and the various &quot;backends&quot; you can use to make the loops run in parallel without changing your loop code. Then, to make sure you've captured the concepts, you can try these <a rel="nofollow" href="http://www.r-exercises.com/2017/07/13/parallel-computing-exercises-foreach-and-doparallel-part-2/" target="_blank">10 parallel computing exercises using foreach</a>, from R-exercises.com. If you get stuck, the <a rel="nofollow" href="http://www.r-exercises.com/2017/07/13/parallel-computing-exercises-foreach-and-doparallel-part-2-solutions/" target="_blank">solutions are available here</a>.</p>
<p>To get started with foreach, can install <a rel="nofollow" href="https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0ahUKEwjVkaCGq6rVAhWmslQKHaDlBeEQFggoMAA&url=https%3A%2F%2Fcran.r-project.org%2Fpackage%3Dforeach&usg=AFQjCNFmwbc1p8ZsAvvR_K3wFA0tAenzLw" target="_blank">the foreach package from CRAN</a>, or simply use any edition of Microsoft R including <a rel="nofollow" href="http://mran.microsoft.com/open/" target="_blank">Microsoft R Open</a> (all come with foreach preinstalled). The foreach package is maintained by Microsoft under the open-source Apache license. </p>
<p>R-exercises: <a rel="nofollow" href="http://www.r-exercises.com/2017/07/13/parallel-computing-exercises-foreach-and-doparallel-part-2" target="_blank">Parallel Computing Exercises: Foreach and DoParallel (Part-2)</a></p>
</div>
	<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://blog.revolutionanalytics.com/2017/07/foreach-exercises.html"> Revolutions</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 width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/TYRAlICULIc" height="1"></a></div>