<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/basics-of-data-table-smooth-data-exploration/"></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/23/basics-of-data-table-smooth-data-exploration/"> 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/speed.jpg" target="_blank"><img sizes="(max-width: 300px) 100vw, 300px" src="https://i1.wp.com/www.r-exercises.com/wp-content/uploads/2017/08/speed-300x169.jpg?resize=300%2C169" alt="" class="wp-image-7601" data-recalc-dims="1"></a></p>
<p>The <code>data.table</code> package provides perhaps the fastest way for data wrangling in R. The syntax is concise and is made to resemble SQL. After studying the basics of <code>data.table</code> and finishing this exercise set successfully you will be able to start easing into using <code>data.table</code> for all your data manipulation needs.</p>
<p>We will use data drawn from the 1980 US Census on married women aged 21–35 with two or more children. The data includes gender of first and second child, as well as information on whether the woman had more than two children, race, age and number of weeks worked in 1979. For more information please refer to the <a rel="nofollow" href="https://cran.r-project.org/web/packages/AER/AER.pdf" target="_blank">reference manual for the package AER</a>.</p>
<p>Answers are available <a rel="nofollow" href="http://www.r-exercises.com/2017/08/23/basics-of-data-table-smooth-data-exploration-solution" target="_blank">here</a>.</p>
<p><strong>Exercise 1</strong><br>
Load the <code>data.table</code> package. Furtermore (install and) load the <code>AER</code> package and run the command <code>data(&quot;Fertility&quot;)</code> which loads the dataset Fertility to your workspace. Turn it into a <code>data.table</code> object.</p>
<p><strong>Exercise 2</strong><br>
Select rows 35 to 50 and print to console its age and work entry.</p>
<p><strong>Exercise 3</strong><br>
Select the last row in the dataset and print to console.</p>
<p><strong>Exercise 4</strong><br>
Count how many women proceeded to have a third child.</p>
<div>
<aside><img src="http://www.r-exercises.com/2017/08/23/basics-of-data-table-smooth-data-exploration/"></aside>
<div><strong>Learn more</strong> about the data.table package 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>work with different data manipulation packages,</li>
<li>know how to import, transform and prepare your dataset for modelling,</li>
<li>and much more.</li>
</ul>
</div>
</div>
<p><strong>Exercise 5</strong><br>
There are four possible gender combinations for the first two children. Which is the most common? Use the <code>by</code> argument.</p>
<p><strong>Exercise 6</strong><br>
By racial composition what is the proportion of woman working four weeks or less in 1979?</p>
<p><strong>Exercise 7</strong><br>
Use <code>%between%</code> to get a subset of woman between 22 and 24 calculate the proportion who had a boy as their firstborn.</p>
<p><strong>Exercise 8</strong><br>
Add a new column, age squared, to the dataset.</p>
<p><strong>Exercise 9</strong><br>
Out of all the racial composition in the dataset which had the lowest proportion of boys for their firstborn. With the same command display the number of observation in each category as well.</p>
<p><strong>Exercise 10</strong><br>
Calculate the proportion of women who have a third child by gender combination of the first two children?</p>
<div>
<h3>Related exercise sets:</h3>
<ol>
<li><a rel="nofollow" href="http://www.r-exercises.com/2015/10/09/vector-exercises/" title="Vector exercises" target="_blank">Vector exercises </a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/2016/11/28/data-frame-exercises-vol-2/" title="Data frame exercises Vol. 2" target="_blank">Data frame exercises Vol. 2 </a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/2017/05/15/instrumental-variables-in-r-exercises-part-1/" title="Instrumental Variables in R exercises (Part-1)" target="_blank">Instrumental Variables in R exercises (Part-1) </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/23/basics-of-data-table-smooth-data-exploration/"> 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/xv9GL-4Mw3U" height="1"></a></div>