<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/list-vol-2-exercises/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://r-exercises.com/2016/12/27/list-exercises-vol-2/"> 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/12/wish-list-1895013_960_720.png?x61433"><img sizes="(max-width: 150px) 100vw, 150px" alt="" class="wp-image-3551" src="https://i1.wp.com/r-exercises.com/wp-content/uploads/2016/12/wish-list-1895013_960_720-150x150.png?resize=150%2C150" data-recalc-dims="1"></a></p>
<p>Answers to the exercises are available <a target="_blank" rel="nofollow" href="http://r-exercises.com/2016/12/27/list-exercises-vol-2-solutions/">here</a>.</p>
<p><strong>Exercise 1</strong></p>
<p>Consider 3 vectors, day, month and year:</p>
<p><code>year=c(2005:2016)<br>
month=c(1:12)<br>
day=c(1:31)<br>
</code></p>
<p>Define a list Date such as:<br>
<code><br>
Date=</code></p>
<p>$year<br>
[1] 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016</p>
<p>$month<br>
[1] 1 2 3 4 5 6 7 8 9 10 11 12</p>
<p>$day<br>
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31</p>
<p><strong>Exercise 2</strong></p>
<p>write an R statement that will replace the values of year element in Date list for <code>c(2000:2010)</code>.</p>
<p><strong>Exercise 3</strong></p>
<p>write an R statement that will delete the value 4 of the month component of the list Date.</p>
<p>
<div>
<aside><img src="http://r-exercises.com/2016/12/27/list-exercises-vol-2/"></aside>
<div><strong>Learn more</strong> about lists in the online courses:
<ul>
<li><a target="_blank" rel="nofollow" href="http://r-exercises.com/product/learn-by-example-statistics-and-data-science-in-r/">Learn By Example: Statistics and Data Science in R</a> (lecture 59)</li>
<li><a target="_blank" rel="nofollow" href="http://r-exercises.com/product/the-comprehensive-statistics-and-data-science-with-r-course/">The Comprehensive Statistics and Data Science with R Course</a> (lectures 69-76)<a target="_blank" rel="nofollow" href="http://r-exercises.com/product/the-comprehensive-statistics-and-data-science-with-r-course/"><br>
</a></li>
<li><a target="_blank" rel="nofollow" href="http://r-exercises.com/product/r-programming-advanced-analytics-in-r-for-data-science/">R Programming: Advanced Analytics In R For Data Science</a> (11 lectures all about lists, ~ 1.5 hrs in total)

</li>
</ul>
<p><strong>Exercise 4</strong></p>
<p>Consider a vector x such that:<br>
<code>x=c(1,3,4,7,11,18,29)</code><br>
Write an R statement that will return a list X2 with components of value:<br>
<code>x*2,x/2,sqrt(x)</code> and names <code>&quot;x*2&quot;,&quot;x/2&quot;,&quot;sqrt(x)&quot;</code></p>
<p><strong>Exercise 5</strong></p>
<p>Consider the X2 list.<br>
Write an R statement that will return a vector:<br>
<code>2.000000 2.645751 3.316625</code></p>
<p><strong>Exercise 6</strong></p>
<p>Write an R statement that will return a concatenation M, of Date and X2 lists.<br>
<code><br>
M<br>
$year<br>
[1] 2000 2001 2002 2003 2004 2005 2006 2007 2008</code></p>
<p>$month<br>
[1] 1 2 3 5 6 7 8 9 10 11 12</p>
<p>$day<br>
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23<br>
[24] 24 25 26 27 28 29 30 31</p>
<p>$`x*2`<br>
[1] 2 6 8 14 22 36 58</p>
<p>$`x/2`<br>
[1] 0.5 1.5 2.0 3.5 5.5 9.0 14.5</p>
<p>$`sqrt(x)`<br>
[1] 1.000000 1.732051 2.000000 2.645751 3.316625 4.242641 5.385165</p>
<p><strong>Exercise 7</strong></p>
<p>Write an R statement that will return a sublist N of M, with components year,x*2 and day.</p>
<p><strong>Exercise 8</strong></p>
<p>Consider the N list.<br>
Write an R statement that will return:<br>
-the length of x*2 vector in N<br>
-the value of the second element of vector year in N</p>
<p><strong>Exercise 9</strong></p>
<p>Consider 3 letters vectors, and 2 numeric vectors:<br>
<code>A=letters[1:4],B=letters[5:10],C=letters[11:15]</code><br>
<code>D=c(1:10),E=c(20:5)</code></p>
<p>Define a list z, with elementes x and y,such that<br>
x is a list with elements A,B,and C;<br>
and y is alist with elements D and E.</p>
<p><strong>Exercise 10</strong><br>
Write an R statement that will return:<br>
-the number on third position on the second vector of the first list of z<br>
-the letter on fifth position on the third vector of the second list of z</p>
<p><strong>Want some extra practice with lists? Please take a look <a target="_blank" rel="nofollow" href="http://r-exercises.com/tag/list">here</a></strong></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/27/list-exercises-vol-2/"> 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/49phqtwpI5A"></a></div></div></div>