<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/soccer-data-sparring-scraping-merging-and-analyzing-exercises/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.r-exercises.com/2017/08/08/soccer-data-sparring-scraping-merging-and-analyzing/?utm_source=rss&utm_medium=rss&utm_campaign=soccer-data-sparring-scraping-merging-and-analyzing"> R-exercises</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><a rel="nofollow" href="https://i1.wp.com/www.r-exercises.com/wp-content/uploads/2017/08/sport-788105__340.jpg" target="_blank"><img sizes="(max-width: 150px) 100vw, 150px" src="https://i1.wp.com/www.r-exercises.com/wp-content/uploads/2017/08/sport-788105__340-150x150.jpg?resize=150%2C150" alt="" class="wp-image-7344" data-recalc-dims="1"></a></p>
<p>
While understanding and spending time improving specific techniques, and strengthening indvidual muscles is important, occasionally it is necessary to do some rounds of actual sparring to see your flow and spot weaknesses. This exercise sets forces you to use all that you have practiced: to scrape links, download data, regular expressions, merge data and then analyze it.
</p>
<p>
We will download data from the website football-data.co.uk that has data on some football/soccer leagues results and odds quoted by bookmakers where you can bet on the results.<br>

</p>
<p>
Answers are available <a rel="nofollow" href="http://r-exercises.com/2017/08/08/soccer-data-sparring-scraping-merging-and-analyzing-solutions/" target="_blank">here</a>.
</p>
<p><strong>Exercise 1</strong></p>
<p>
Use R to scan the <a rel="nofollow" href="http://www.football-data.co.uk/germanym.php" target="_blank">German</a> section on football-data.co.uk for any links and save them in a character vector called <code>all_links</code>. There are many ways to accomplish this.
</p>
<p><strong>Exercise 2</strong></p>
<p>
Among the links you found should be a number pointing to comma-separated values files with data on Bundesliga 1 and 2 separated by season. Now update <code>all_links</code> vector so that only links to <code>csv</code> files remain. Use regular expressions.
</p>
<div>
<aside><img src="http://www.r-exercises.com/2017/08/08/soccer-data-sparring-scraping-merging-and-analyzing/?utm_source=rss&utm_medium=rss&utm_campaign=soccer-data-sparring-scraping-merging-and-analyzing"></aside>
<div><strong>Learn more</strong> about Data Pre-Processing in the online course <a rel="nofollow" href="http://www.r-exercises.com/product/r-data-pre-processing-data-management-shape-your-data/" target="_blank">R Data Pre-Processing &amp; Data Management – Shape your Data!</a>. In this course you will learn how to:
<ul>
<li>import data into R in several ways while also beeing able to identify a suitable import tool</li>
<li>use SQL code within R</li>
<li>And much more</li>
</ul>
</div>
</div>
<p><strong>Exercise 3</strong></p>
<p>
Again, update <code>all_links</code> so that only links to csv tables ‘from Bundesliga 1 from Season 1993/1994 to 2013/2014 inclusive’ remain.
</p>
<p><strong>Exercise 4</strong></p>
<p>
Import to a list in your workspace all the 21 remaining csv files in <code>all_links</code>, each one as a <code>data.frame</code>. Use <code>read.csv</code>, with the url and <code>na.strings = c(&quot;&quot;, &quot;NA&quot;)</code>. Not that you might need to add a prefix for them, so the links are complete.
</p>
<p><strong>Exercise 5</strong></p>
<p>
Take the list and generate a one big data.frame with all the <code>data.frame</code>s previously imported. One way to do this is using <code>rbind.fill</code> function from a well-known package. Name the new <code>data.frame</code> as <code>bundesl</code>.
</p>
<p><strong>Exercise 6</strong></p>
<p>
Take a good look at the new dataset. Our <code>read.csv</code> did not work perfectly on this data: it turns out that there are some empty rows and empty columns, identify and count them. Update the <code>bundesl</code> so it no longer has empty rows m nor columns.
</p>
<p><strong>Exercise 7</strong></p>
<p>
Format the Date column so R understands using <code>as.Date()</code>.
</p>
<p><strong>Exercise 8</strong></p>
<p>
Remove all columns which are not 100% complete, and the variable <code>Div</code> as well.
</p>
<p><strong>Exercise 9</strong></p>
<p>
Which are the top 3 teams in terms of numbers of wins in Bundesliga 1 for our period? You are free to use base-R functions or any package. Be warned that his task is not as simple as it seems due the nature in the data and small inconsitency in the data.
</p>
<p><strong>Exercise 10</strong></p>
<p>
Which team has held the longest winning streak in our data?</p>
<div>
<h3>Related exercise sets:</h3>
<ol>
<li><a rel="nofollow" href="http://www.r-exercises.com/2017/05/24/data-wrangling-part-1-io/" title="Data wrangling : I/O (Part-1)" target="_blank">Data wrangling : I/O (Part-1) </a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/2017/06/07/data-wrangling-io-part-2/" title="Data wrangling : I/O (Part-2)" target="_blank">Data wrangling : I/O (Part-2) </a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/2016/12/20/web-scraping-exercises/" title="Web Scraping Exercises" target="_blank">Web Scraping Exercises </a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/start-here-to-learn-r/" target="_blank">Explore all our (>1000) R exercises</a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/r-courses/" target="_blank">Find an R course using our R Course Finder</a> directory</li>
</ol>
</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://www.r-exercises.com/2017/08/08/soccer-data-sparring-scraping-merging-and-analyzing/?utm_source=rss&utm_medium=rss&utm_campaign=soccer-data-sparring-scraping-merging-and-analyzing"> R-exercises</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/klSLPxwCDos" height="1"></a></div>