<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/select-and-query-exercise/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://r-exercises.com/2016/12/06/select-and-query-exercise/"> R-exercises</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><a target="_blank" rel="nofollow" href="http://r-exercises.com/wp-content/uploads/2016/11/Selecting-a-Real-Estate-Agent-Red.png?x61433"><img sizes="(max-width: 150px) 100vw, 150px" alt="selecting-a-real-estate-agent-red" class="wp-image-3067" src="https://i2.wp.com/r-exercises.com/wp-content/uploads/2016/11/Selecting-a-Real-Estate-Agent-Red-150x150.png?resize=150%2C150" data-recalc-dims="1"></a></p>
<p>In this exercise we cover the basics on selecting and extracting data using queries. We add a few other materials into it. This should prepare you for the next exercise: Basic Decision Tree. The purpose of this is to give you the 20 percent of the tools to get 80 percent of work done. You will be off and running plotting simple decision trees. It will be helpful to read up on str(),colnames() and data.frame() command.</p>
<p>Answers to the exercises are available <a target="_blank" rel="nofollow" href="http://r-exercises.com/2016/12/06/select-and-query-exercise-2/">here</a>.</p>
<p>If you obtained a different (correct) answer than those listed on the solutions page, please feel free to post your answer as a comment on that page.</p>
<p><strong>Exercise 1</strong><br>
create vectors. Hint: use c outside brackets to indicate multiple items<br>
a. Create a numeric vector that includes the numbers 4, 5,6,8 and 3 (exact order). Store this in the variable a<br>
b. Create a character vector that includes the characters <code>&quot;apple&quot;,&quot;chair&quot;,&quot;jetplane&quot;,&quot;salmon&quot;,&quot;island&quot;</code>. Store this in the variable b<br>
c. Create a boolean vector TRUE,TRUE,FALSE,TRUE,FALSE. Note that boolean is sensitive to letter case. Store this in c</p>
<p><strong>Exercise 2</strong><br>
create a dataframe using the variables a,b and c. Store this in df</p>
<p><strong>Exercise 3</strong><br>
use the <code>str()</code> command to see the dataframe</p>
<p><strong>Exercise 4</strong><br>
print the column names of df</p>
<p><strong>Exercise 5</strong><br>
change the column names of df to “id”,”wish”,”real”. View the dataframe again using the <code>str()</code> command.</p>
<p><strong>Exercise 6</strong><br>
quick selecting exercise<br>
a.select the first column of the df using column name<br>
b.select the row where id==3. Use this logic to select the row.<br>
c.Now use the index method to select the first row in df<br>
d.select the second column of the df using index method<br>
e.select the second item in the third row of df</p>
<p><strong>Exercise 7</strong><br>
attach/load the iris dataset and use the <code>str()</code> command to see the dataset</p>
<p><strong>Exercise 8</strong><br>
change the column names of iris to <code>&quot;sl&quot;,&quot;sw&quot;,&quot;sl&quot;,&quot;pw&quot;,&quot;s&quot;</code></p>
<p><strong>Exercise 9</strong><br>
select exercise using the iris dataset<br>
a. select the rows where ‘sw’ is 3<br>
b. select the first element of the second cloumn<br>
c. select the first 6 rows of the dataset<br>
d. select the last 6 rows of the dataset<br>
e.select every column except the s column</p>
<p><strong>Exercise 10</strong><br>
select all the rows where sl is greater than 5 and store all the sample in iris_2 making sure to exclude the s column</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="http://r-exercises.com/2016/12/06/select-and-query-exercise/"> 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 title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/LeW7fZsSCtM"></a></div>