<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/beyond-the-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/09/06/beyond-the-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://i0.wp.com/www.r-exercises.com/wp-content/uploads/2017/08/33232402401_03b48d3268_m.jpg" target="_blank"><img sizes="(max-width: 300px) 100vw, 300px" src="https://i2.wp.com/www.r-exercises.com/wp-content/uploads/2017/08/33232402401_03b48d3268_m-300x298.jpg?resize=300%2C298" alt="" class="wp-image-7779" data-recalc-dims="1"></a></p>
<p>This exercise set provides practice using the fast and concise <code>data.table</code> package. If you are new to the syntax it is recommended that you start by solving <a rel="nofollow" href="http://www.r-exercises.com/2017/08/23/basics-of-data-table-smooth-data-exploration/" target="_blank">the set on the basics of data.table</a> before attempting this one.</p>
<p>We will use data on used cars (Toyota Corollas) on sale during 2004 in the Netherlands. There are 1436 observations with information on the price at which it is offered for sale, age, mileage and more, see full variable description <a rel="nofollow" href="http://www.r-exercises.com/2017/08/31/data-description-for-exercise-beyond-the-basics-of-data-table-smooth-data-exploration" target="_blank">here</a>.</p>
<p>Answers are available <a rel="nofollow" href="http://www.r-exercises.com/2017/09/06/beyond-the-basics-of-data-table-smooth-data-exploration-solutions" target="_blank">here</a>.</p>
<p> </p>
<p><strong>Exercise 1</strong><br>
Load the <a rel="nofollow" href="http://www.r-exercises.com/wp-content/uploads/2017/08/toy_cor.csv" target="_blank">data</a> available to your working environment using <code>fread()</code>, don’t forget to load the <code>data.table</code> package first.</p>
<p><strong>Exercise 2</strong><br>
Using one line of code print out the most common car model in the data, and the number of times it appears.</p>
<p><strong>Exercise 3</strong><br>
Print out the mean and median price of the 10 most common models.</p>
<p><strong>Exercise 4</strong><br>
Delete all columns that have Guarantee in its name.</p>
<p><strong>Exercise 5</strong><br>
Add a new column which is the squared deviation of price from the average price of cars the same color.</p>
<p><strong>Exercise 6</strong><br>
Use a combintation of <code>.SDcols</code> and <code>lapply</code> to get the mean value of columns 18 through 35</p>
<p><strong>Exercise 7</strong><br>
Print the most common color by age in years?</p>
<div>
<aside><img src="http://www.r-exercises.com/2017/09/06/beyond-the-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 8</strong><br>
For the dummy variables in columns 18:35 recode 0 to -1. You might want to use the <code>set</code> function here.</p>
<p><strong>Exercise 9</strong><br>
Use the <code>set</code> function to add “yuck!” to the varible <code>Fuel_Type</code> if it is not petrol. Just because…</p>
<p><strong>Exercise 10</strong><br>
Using <code>.SDcols</code> and one command create two new variables, log of <code>Weight</code> and <code>Price</code>.</p>
<p> </p>
<p>(Painting by <a rel="nofollow" href="https://www.flickr.com/photos/pedrosimoes7/33232402401/in/photostream/" target="_blank">José de Almada</a>)</p>
<div>
<h3>Related exercise sets:</h3>
<ol>
<li><a rel="nofollow" href="http://www.r-exercises.com/2017/08/23/basics-of-data-table-smooth-data-exploration/" title="Basics of data.table: Smooth data exploration" target="_blank">Basics of data.table: Smooth data exploration </a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/2016/07/26/stock-prices-analysis-part-1-exercises/" title="Stock prices analysis  part 1 exercises" target="_blank">Stock prices analysis part 1 exercises </a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/2017/06/15/data-manipulation-with-data-table-part-1/" title="Data Manipulation with Data Table  -Part 1" target="_blank">Data Manipulation with Data Table -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/09/06/beyond-the-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/DAtxAAWU09w" height="1"></a></div>