Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

In the exercises below we cover the basics of lists. Before proceeding, first read section 6.1-6.2 of An Introduction to R, and the help pages for the `sum`, `length`, `strsplit`, and `setdiff` functions.

Answers to the exercises are available here.

Exercise 1
If:
```p <- c(2,7,8), q <- c("A", "B", "C") and x <- list(p, q), then what is the value of x[2]? a. NULL b. "A" "B" "C" c. "7"```

`Exercise 2 If: w <- c(2, 7, 8) v <- c("A", "B", "C") x <- list(w, v), then which R statement will replace "A" in x with "K". a. x[[2]] <- "K" b. x[[2]][1] <- "K" c. x[[1]][2] <- "K" `

`Exercise 3 If a <- list ("x"=5, "y"=10, "z"=15), which R statement will give the sum of all elements in a? a. sum(a) b. sum(list(a)) c. sum(unlist(a))`

`Exercise 4 If Newlist <- list(a=1:10, b="Good morning", c="Hi"), write an R statement that will add 1 to each element of the first vector in Newlist.`

`Exercise 5 If b <- list(a=1:10, c="Hello", d="AA"), write an R expression that will give all elements, except the second, of the first vector of b.`

`Exercise 6 Let x <- list(a=5:10, c="Hello", d="AA"), write an R statement to add a new item z = "NewItem" to the list x.`

`Exercise 7 Consider y <- list("a", "b", "c"), write an R statement that will assign new names "one", "two" and "three" to the elements of y.`

`Exercise 8 If x <- list(y=1:10, t="Hello", f="TT", r=5:20), write an R statement that will give the length of vector r of x.`

`Exercise 9 Let string <- "Grand Opening", write an R statement to split this string into two and return the following output: [[1]] [1] "Grand"`

`[[2]] [1] "Opening" `

`Exercise 10 Let: y <- list("a", "b", "c") and q <- list("A", "B", "C", "a", "b", "c"). Write an R statement that will return all elements of q that are not in y, with the following result: [[1]] [1] "A"`

`[[2]] [1] "B"`

`[[3]] [1] "C" `

``` var vglnk = {key: '949efb41171ac6ec1bf7f206d57e90b8'}; (function(d, t) { var s = d.createElement(t); s.type = 'text/javascript'; s.async = true; s.src = '//cdn.viglink.com/api/vglnk.js'; var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r); }(document, 'script')); RelatedShareTweetTo leave a comment for the author, please follow the link and comment on their blog: R-exercises. R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.```
``` [{"@context":"https:\/\/schema.org","@graph":[{"@type":"Organization","@id":"https:\/\/www.r-bloggers.com#Organization","name":"R-bloggers","url":"http:\/\/www.r-bloggers.com","sameAs":[],"logo":{"@type":"ImageObject","url":"http:\/\/www.r-bloggers.com\/wp-content\/uploads\/2020\/07\/R_blogger_logo_02.png","width":"1061","height":"304"},"contactPoint":{"@type":"ContactPoint","contactType":"technical support","telephone":"","url":"https:\/\/www.r-bloggers.com\/contact-us\/"}},{"@type":"WebSite","@id":"https:\/\/www.r-bloggers.com#website","headline":"R-bloggers","name":"R-bloggers","description":"R news and tutorials contributed by hundreds of R bloggers","url":"https:\/\/www.r-bloggers.com","potentialAction":{"@type":"SearchAction","target":"https:\/\/www.r-bloggers.com\/?s={search_term_string}","query-input":"required name=search_term_string"},"publisher":{"@id":"https:\/\/www.r-bloggers.com#Organization"}},{"@context":"https:\/\/schema.org","@type":"WebPage","@id":"https:\/\/www.r-bloggers.com\/list-exercises\/#webpage","name":"List exercises | R-bloggers","url":"https:\/\/www.r-bloggers.com\/list-exercises\/","lastReviewed":"2015-12-31T01:00:30-06:00","reviewedBy":{"@type":"Organization","logo":{"@type":"ImageObject","url":"http:\/\/www.r-bloggers.com\/wp-content\/uploads\/2020\/07\/R_blogger_logo_02.png","width":"1061","height":"304"},"name":"R-bloggers"},"inLanguage":"en-US","description":"In the exercises below we cover the basics of lists. Before proceeding, first read section 6.1-6.2 of An Introduction to R, and the help pages for the sum, length, strsplit, and setdiff functions.\nAnswers to the exercises are available here.\nExercise 1...","primaryImageOfPage":{"@id":"https:\/\/www.r-bloggers.com\/list-exercises\/#primaryimage"},"mainContentOfPage":[[{"@context":"https:\/\/schema.org","@type":"SiteNavigationElement","@id":"https:\/\/www.r-bloggers.com\/#top nav","name":"Home","url":"https:\/\/www.r-bloggers.com"},{"@context":"https:\/\/schema.org","@type":"SiteNavigationElement","@id":"https:\/\/www.r-bloggers.com\/#top nav","name":"About","url":"http:\/\/www.r-bloggers.com\/about\/"},{"@context":"https:\/\/schema.org","@type":"SiteNavigationElement","@id":"https:\/\/www.r-bloggers.com\/#top nav","name":"RSS","url":"https:\/\/feeds.feedburner.com\/RBloggers"},{"@context":"https:\/\/schema.org","@type":"SiteNavigationElement","@id":"https:\/\/www.r-bloggers.com\/#top nav","name":"add your blog!","url":"http:\/\/www.r-bloggers.com\/add-your-blog\/"},{"@context":"https:\/\/schema.org","@type":"SiteNavigationElement","@id":"https:\/\/www.r-bloggers.com\/#top nav","name":"Learn R","url":"https:\/\/www.r-bloggers.com\/how-to-learn-r-2\/"},{"@context":"https:\/\/schema.org","@type":"SiteNavigationElement","@id":"https:\/\/www.r-bloggers.com\/#top nav","name":"R jobs","url":"https:\/\/www.r-users.com\/"},{"@context":"https:\/\/schema.org","@type":"SiteNavigationElement","@id":"https:\/\/www.r-bloggers.com\/#top nav","name":"Submit a new job (it's free)","url":"https:\/\/www.r-users.com\/submit-job\/"},{"@context":"https:\/\/schema.org","@type":"SiteNavigationElement","@id":"https:\/\/www.r-bloggers.com\/#top nav","name":"Browse latest jobs (also free)","url":"https:\/\/www.r-users.com\/"},{"@context":"https:\/\/schema.org","@type":"SiteNavigationElement","@id":"https:\/\/www.r-bloggers.com\/#top nav","name":"Contact us","url":"http:\/\/www.r-bloggers.com\/contact-us\/"}]],"isPartOf":{"@id":"https:\/\/www.r-bloggers.com#website"},"breadcrumb":{"@id":"https:\/\/www.r-bloggers.com\/list-exercises\/#breadcrumb"}},{"@type":"BreadcrumbList","@id":"https:\/\/www.r-bloggers.com\/list-exercises\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"item":{"@id":"https:\/\/www.r-bloggers.com","name":"R-bloggers"}},{"@type":"ListItem","position":2,"item":{"@id":"https:\/\/www.r-bloggers.com\/category\/r-bloggers\/","name":"R bloggers"}},{"@type":"ListItem","position":3,"item":{"@id":"https:\/\/www.r-bloggers.com\/list-exercises\/","name":"List exercises | R-bloggers"}}]},{"@type":"Article","@id":"https:\/\/www.r-bloggers.com\/list-exercises\/#article","url":"https:\/\/www.r-bloggers.com\/list-exercises\/","inLanguage":"en-US","mainEntityOfPage":"https:\/\/www.r-bloggers.com\/list-exercises\/#webpage","headline":"List exercises | R-bloggers","description":"In the exercises below we cover the basics of lists. Before proceeding, first read section 6.1-6.2 of An Introduction to R, and the help pages for the sum, length, strsplit, and setdiff functions.\nAnswers to the exercises are available here.\nExercise 1...","articleBody":"In the exercises below we cover the basics of lists. Before proceeding, first read section 6.1-6.2 of An Introduction to R, and the help pages for the sum, length, strsplit, and setdiff functions. Answers to the exercises are available here. Exercise 1 If: p","keywords":"","datePublished":"2015-12-31T01:00:30-06:00","dateModified":"2015-12-31T01:00:30-06:00","author":{"@type":"Person","name":"r-exercises","description":"","url":"https:\/\/www.r-bloggers.com\/author\/r-exercises\/","sameAs":["http:\/\/r-exercises.com"],"image":{"@type":"ImageObject","url":"https:\/\/secure.gravatar.com\/avatar\/d42d0b3ccf7cd08ff0ea56cc54aac107?s=96&d=mm&r=g","height":96,"width":96}},"publisher":{"@id":"https:\/\/www.r-bloggers.com#Organization"},"image":{"@type":"ImageObject","@id":"https:\/\/www.r-bloggers.com\/list-exercises\/#primaryimage","url":"http:\/\/www.r-bloggers.com\/wp-content\/uploads\/2020\/07\/R_logo.svg_.png","width":"1280","height":"992"},"isPartOf":{"@id":"https:\/\/www.r-bloggers.com\/list-exercises\/#webpage"}}]}] var snp_f = []; var snp_hostname = new RegExp(location.host); var snp_http = new RegExp("^(http|https)://", "i"); var snp_cookie_prefix = ''; var snp_separate_cookies = false; var snp_ajax_url = 'https://www.r-bloggers.com/wp-admin/admin-ajax.php'; var snp_ajax_nonce = 'b2af198708'; var snp_ignore_cookies = false; var snp_enable_analytics_events = false; var snp_enable_mobile = false; var snp_use_in_all = false; var snp_excluded_urls = []; snp_excluded_urls.push(''); Never miss an update! Subscribe to R-bloggers to receive e-mails with the latest R posts. (You will not see this message again.) Click here to close (This popup will not appear again).snp-pop-109583 .snp-theme6 { max-width: 700px;} .snp-pop-109583 .snp-theme6 h1 {font-size: 17px;} .snp-pop-109583 .snp-theme6 { color: #a0a4a9;} .snp-pop-109583 .snp-theme6 .snp-field ::-webkit-input-placeholder { color: #a0a4a9;} .snp-pop-109583 .snp-theme6 .snp-field :-moz-placeholder { color: #a0a4a9;} .snp-pop-109583 .snp-theme6 .snp-field :-ms-input-placeholder { color: #a0a4a9;} .snp-pop-109583 .snp-theme6 .snp-field input { border: 1px solid #a0a4a9;} .snp-pop-109583 .snp-theme6 .snp-field { color: #000000;} .snp-pop-109583 .snp-theme6 { background: #f2f2f2;}jQuery(document).ready(function() { }); var CaptchaCallback = function() { jQuery('.g-recaptcha').each(function(index, el) { grecaptcha.render(el, { 'sitekey' : '' }); }); }; window.FPConfig= { delay: 0, ignoreKeywords: ["\/wp-admin","\/wp-login.php","\/cart","add-to-cart","logout","#","?",".png",".jpeg",".jpg",".gif",".svg"], maxRPS: 3, hoverDelay: 50 }; _stq = window._stq || []; _stq.push([ 'view', {v:'ext',j:'1:7.3.2',blog:'11524731',post:'114186',tz:'-6',srv:'www.r-bloggers.com'} ]); _stq.push([ 'clickTrackerInit', '11524731', '114186' ]); jQuery(document).ready(function (\$) { //\$( document ).ajaxStart(function() { //}); for (var i = 0; i < document.forms.length; ++i) { var form = document.forms[i]; if (\$(form).attr("method") != "get") { \$(form).append('<input type="hidden" name="iLk_OoNZATdV" value="W84S_c1w*Ka7" />'); } if (\$(form).attr("method") != "get") { \$(form).append('<input type="hidden" name="pYbxk_z" value="0eJkL7w" />'); } if (\$(form).attr("method") != "get") { \$(form).append('<input type="hidden" name="xXGyZbrfKpq" value="gGW7HJCYOhl" />'); } } \$(document).on('submit', 'form', function () { if (\$(this).attr("method") != "get") { \$(this).append('<input type="hidden" name="iLk_OoNZATdV" value="W84S_c1w*Ka7" />'); } if (\$(this).attr("method") != "get") { \$(this).append('<input type="hidden" name="pYbxk_z" value="0eJkL7w" />'); } if (\$(this).attr("method") != "get") { \$(this).append('<input type="hidden" name="xXGyZbrfKpq" value="gGW7HJCYOhl" />'); } return true; }); jQuery.ajaxSetup({ beforeSend: function (e, data) { //console.log(Object.getOwnPropertyNames(data).sort()); //console.log(data.type); if (data.type !== 'POST') return; if (typeof data.data === 'object' && data.data !== null) { data.data.append("iLk_OoNZATdV", "W84S_c1w*Ka7"); data.data.append("pYbxk_z", "0eJkL7w"); data.data.append("xXGyZbrfKpq", "gGW7HJCYOhl"); } else { data.data = data.data + '&iLk_OoNZATdV=W84S_c1w*Ka7&pYbxk_z=0eJkL7w&xXGyZbrfKpq=gGW7HJCYOhl'; } } }); }); ```