<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/saddling-up-getting-on-the-horse-for-the-first-time/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://www.mango-solutions.com/blog/saddling-up-getting-on-the-horse-for-the-first-time"> Mango Solutions</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p> <img sizes="100vw" src="https://i1.wp.com/www.mango-solutions.com/blog/images/7/0/1/7/f/7017f3eaa985cbace350ac713e633afd3f804334-tough-going-in-r-blog-header.png?w=456&ssl=1" data-recalc-dims="1"></p>
<h4><em>Laura Swales, Marketing and Events Assistant</em></h4>
<p>This year at Mango we’re proudly sponsoring the <a rel="nofollow" href="https://www.bathcatsanddogshome.org.uk/" target="_blank">Bath Cats &amp; Dogs<br>
Home</a>. To start our fundraising<br>
for them, we decided to run a sweepstake on the Grand National. We asked<br>
for £2 per horse, which would go to the cats and dogs home and the<br>
winner was promised a bottle of wine for their charitable efforts.</p>
<p>Working in a Data Science company I knew that I couldn’t simply pick<br>
names out of a hat for the sweepstake, ‘That’s not truly random!’ they<br>
would cry. So in my hour of need, I turned to our two university<br>
placement students Owen and Caroline to help me randomise the names in<br>
R.</p>
<h3>Non-starter</h3>
<p>To use an appropriate horse-based metaphor, I would class myself as a<br>
‘non-starter’ in R – I’m not even near the actual race! My knowledge is<br>
practically non-existent (‘Do you just type alot of random letters?’)<br>
and up until this blog I didn’t even have RStudio on my laptop.</p>
<h3>The first hurdle</h3>
<p>We began by creating a list of the people who had entered the<br>
sweepstake. With some people betting on more than one horse their name<br>
was entered as many times as needed to correlate to how many bets they<br>
had laid down.</p>
<pre><code>people_list &lt;- c(&quot;Matt Glover&quot;, &quot;Matt Glover&quot;, &quot;Ed Gash&quot;,
                 &quot;Ed Gash&quot;, &quot;Ed Gash&quot;, &quot;Lisa S&quot;, &quot;Toby&quot;,
                 &quot;Jen&quot;, &quot;Jen&quot;, &quot;Liz&quot;, &quot;Liz&quot;, &quot;Andrew M&quot;,
                 &quot;Nikki&quot;, &quot;Chris James&quot;, &quot;Yvi&quot;, &quot;Yvi&quot;,
                 &quot;Yvi&quot;, &quot;Beany&quot;, &quot;Karina&quot;, &quot;Chrissy&quot;, &quot;Enrique&quot;,
                 &quot;Pete&quot;, &quot;Karis&quot;, &quot;Laura&quot;, &quot;Ryan&quot;, &quot;Ryan&quot;, &quot;Ryan&quot;,
                 &quot;Ryan&quot;, &quot;Ryan&quot;, &quot;Owen&quot;, &quot;Rich&quot;, &quot;Rich&quot;, &quot;Matt A&quot;,
                 &quot;Matt A&quot;, &quot;Matt A&quot;, &quot;Matt A&quot;, &quot;Matt A&quot;, &quot;Matt A&quot;, 
                 &quot;Matt A&quot;, &quot;Matt A&quot;)</code></pre>
<p>I had now associated all the names with the object called <code>people_list</code>.<br>
Next I created an object that contained numbers 1-40 to represent each<br>
horse.</p>
<pre><code>horses_list &lt;- 1:40</code></pre>
<p>With the two sets of values ready to go, I wanted to display them in a<br>
table format to make it easier to match names and numbers.</p>
<pre><code>assign &lt;- data.frame(Runners = horses_list, People = people_list)
head(assign)

##   Runners      People
## 1       1 Matt Glover
## 2       2 Matt Glover
## 3       3     Ed Gash
## 4       4     Ed Gash
## 5       5     Ed Gash
## 6       6      Lisa S</code></pre>
<p>Now the data appeared in a table, but had not been randomised. To do<br>
this I used the <code>sample</code> function to jumble up the <code>people_list</code> names.</p>
<pre><code>assign &lt;- data.frame(horses_list, sample(people_list))</code></pre>
<h3>Free Rein</h3>
<p>Success! I had a list of numbers (1-40) representing the horses and a<br>
randomly jumbled up list of those taking part in the sweepstake.</p>
<p>At the time of writing (In RMarkdown!), unfortunately fate had randomly<br>
selected me the favourite to win. As you can imagine, this is something<br>
that will not make you popular in the office.</p>
<h3>My First Trot</h3>
<p>I hope you enjoyed my first attempt in R. I will definitely use it again<br>
to randomise our next sweepstake, though under intense supervision. I<br>
can still hear the cries of ‘FIX!’ around the office. It’s always an<br>
awkward moment when you win your own sweepstake…</p>
<p>Despite the controversy, it was fun to try out R in an accessible way<br>
and it helped me understand some of the basic functions available.<br>
Perhaps I’ll sit in on the next <a rel="nofollow" href="https://www.londonr.org/" target="_blank">LondonR</a><br>
workshop and learn some more!</p>
<p>If you’d like to find out more about the Bath Cats &amp; Dogs Home please<br>
visit <a rel="nofollow" href="https://www.bathcatsanddogshome.org.uk/" target="_blank">here.</a></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="https://www.mango-solutions.com/blog/saddling-up-getting-on-the-horse-for-the-first-time"> Mango Solutions</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/5VYCCMWsIMg" height="1"></a></div>