{"id":30,"date":"2022-04-19T01:54:42","date_gmt":"2022-04-19T01:54:42","guid":{"rendered":"https:\/\/libraryresources.nse.org.ng\/introduction2r\/chapter\/chapter-5-indexing-subsetting\/"},"modified":"2026-03-16T14:30:57","modified_gmt":"2026-03-16T14:30:57","slug":"chapter-5-indexing-subsetting","status":"publish","type":"chapter","link":"https:\/\/libraryresources.nse.org.ng\/introduction2r\/chapter\/chapter-5-indexing-subsetting\/","title":{"raw":"Chapter 5 - Indexing and Subsetting","rendered":"Chapter 5 &#8211; Indexing and Subsetting"},"content":{"raw":"In this chapter, we are taking our first steps into data exploration through indexing and subsetting. In both cases, this is about taking a quick look at one or more data points in our matrices or datasets to extract some information. Similarly, subsetting allows us to create smaller datasets based on the selection of data points or variables that meet specific conditions.\n\nIn addition to working with numeric matrices and dataset variables, we will also encounter logical operators and expressions again and see why they are so useful in understanding our data.\n<div class=\"textbox textbox--learning-objectives\"><header class=\"textbox__header\">\n<p class=\"textbox__title\">Learning Objectives<\/p>\n\n<\/header>\n<div class=\"textbox__content\">\n\nIn this chapter, we will learn:\n<ul>\n \t<li>what indexing means;<\/li>\n \t<li>how to index data points in a matrix;<\/li>\n \t<li>what subsetting means;<\/li>\n \t<li>how to subset elements of a dataset.<\/li>\n<\/ul>\n<\/div>\n<\/div>\nThe first half of the video below focuses on indexing a matrix. The second half focuses on subsetting a dataset. Watch the video below or at the <a href=\"https:\/\/vimeo.com\/717351393\">link<\/a>.\n\n[embed]https:\/\/vimeo.com\/717351393[\/embed]\n\nThis chapter concludes our first steps with the R language. In the next chapter, we will work on what to do when our code fails or returns an error message in the console.\n<div class=\"textbox textbox--key-takeaways\"><header class=\"textbox__header\">\n<p class=\"textbox__title\">Key functions used in this chapter<\/p>\n\n<\/header>\n<div class=\"textbox__content\">\n<ul>\n \t<li><strong>set.seed()<\/strong>: the function that determines how R selects random numbers;<\/li>\n \t<li><strong>subset()<\/strong>: the function that subsets datasets based on specific conditions.<\/li>\n<\/ul>\n<\/div>\n<\/div>\nCheck your understanding by taking the quiz below.\n\nThe original version of this chapter contained H5P content. You may want to remove or replace this element.","rendered":"<p>In this chapter, we are taking our first steps into data exploration through indexing and subsetting. In both cases, this is about taking a quick look at one or more data points in our matrices or datasets to extract some information. Similarly, subsetting allows us to create smaller datasets based on the selection of data points or variables that meet specific conditions.<\/p>\n<p>In addition to working with numeric matrices and dataset variables, we will also encounter logical operators and expressions again and see why they are so useful in understanding our data.<\/p>\n<div class=\"textbox textbox--learning-objectives\">\n<header class=\"textbox__header\">\n<p class=\"textbox__title\">Learning Objectives<\/p>\n<\/header>\n<div class=\"textbox__content\">\n<p>In this chapter, we will learn:<\/p>\n<ul>\n<li>what indexing means;<\/li>\n<li>how to index data points in a matrix;<\/li>\n<li>what subsetting means;<\/li>\n<li>how to subset elements of a dataset.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<p>The first half of the video below focuses on indexing a matrix. The second half focuses on subsetting a dataset. Watch the video below or at the <a href=\"https:\/\/vimeo.com\/717351393\">link<\/a>.<\/p>\n<p><iframe loading=\"lazy\" id=\"oembed-1\" title=\"Chapter 5 - Indexing and Subsetting\" src=\"https:\/\/player.vimeo.com\/video\/717351393?dnt=1&amp;app_id=122963\" width=\"500\" height=\"281\" frameborder=\"0\"><\/iframe><\/p>\n<p>This chapter concludes our first steps with the R language. In the next chapter, we will work on what to do when our code fails or returns an error message in the console.<\/p>\n<div class=\"textbox textbox--key-takeaways\">\n<header class=\"textbox__header\">\n<p class=\"textbox__title\">Key functions used in this chapter<\/p>\n<\/header>\n<div class=\"textbox__content\">\n<ul>\n<li><strong>set.seed()<\/strong>: the function that determines how R selects random numbers;<\/li>\n<li><strong>subset()<\/strong>: the function that subsets datasets based on specific conditions.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<p>Check your understanding by taking the quiz below.<\/p>\n<p>The original version of this chapter contained H5P content. You may want to remove or replace this element.<\/p>\n","protected":false},"author":1,"menu_order":5,"template":"","meta":{"pb_show_title":"","pb_short_title":"","pb_subtitle":"","pb_authors":[],"pb_section_license":""},"chapter-type":[49],"contributor":[],"license":[],"class_list":["post-30","chapter","type-chapter","status-publish","hentry","chapter-type-numberless"],"part":18,"_links":{"self":[{"href":"https:\/\/libraryresources.nse.org.ng\/introduction2r\/wp-json\/pressbooks\/v2\/chapters\/30","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/libraryresources.nse.org.ng\/introduction2r\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/libraryresources.nse.org.ng\/introduction2r\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/libraryresources.nse.org.ng\/introduction2r\/wp-json\/wp\/v2\/users\/1"}],"version-history":[{"count":1,"href":"https:\/\/libraryresources.nse.org.ng\/introduction2r\/wp-json\/pressbooks\/v2\/chapters\/30\/revisions"}],"predecessor-version":[{"id":31,"href":"https:\/\/libraryresources.nse.org.ng\/introduction2r\/wp-json\/pressbooks\/v2\/chapters\/30\/revisions\/31"}],"part":[{"href":"https:\/\/libraryresources.nse.org.ng\/introduction2r\/wp-json\/pressbooks\/v2\/parts\/18"}],"metadata":[{"href":"https:\/\/libraryresources.nse.org.ng\/introduction2r\/wp-json\/pressbooks\/v2\/chapters\/30\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/libraryresources.nse.org.ng\/introduction2r\/wp-json\/wp\/v2\/media?parent=30"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/libraryresources.nse.org.ng\/introduction2r\/wp-json\/pressbooks\/v2\/chapter-type?post=30"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/libraryresources.nse.org.ng\/introduction2r\/wp-json\/wp\/v2\/contributor?post=30"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/libraryresources.nse.org.ng\/introduction2r\/wp-json\/wp\/v2\/license?post=30"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}