{"id":26,"date":"2022-04-19T01:53:01","date_gmt":"2022-04-19T01:53:01","guid":{"rendered":"https:\/\/libraryresources.nse.org.ng\/introduction2r\/chapter\/chapter-3-objects-vectors-functions\/"},"modified":"2026-03-16T14:30:57","modified_gmt":"2026-03-16T14:30:57","slug":"chapter-3-objects-vectors-functions","status":"publish","type":"chapter","link":"https:\/\/libraryresources.nse.org.ng\/introduction2r\/chapter\/chapter-3-objects-vectors-functions\/","title":{"raw":"Chapter 3 - Objects, Vectors, and Functions","rendered":"Chapter 3 &#8211; Objects, Vectors, and Functions"},"content":{"raw":"Now that we are familiar with our interface, it is time to get started with the actual R language. As we know from the previous chapter, R is a sophisticated calculator, specifically appropriate for statistics and data science.\n\nI highly recommend following along with the videos below in your own R Studio Cloud Workspace.\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 cover the following topics:\n<ul>\n \t<li>objects;<\/li>\n \t<li>vectors;<\/li>\n \t<li>functions.<\/li>\n<\/ul>\n<\/div>\n<\/div>\nWith objects, vectors and functions, we are really getting into the R language so this is where things get serious.\n\nFor those of you taking a class, you will be provided an empty script with only the instructions. You should type the tutorial code as you follow along. Writing code yourself, as opposed to just watching the videos or just running code provided by someone else, is the best way to learn and get more comfortable.\n<h1>Part 1 - Introducing objects, vectors, and functions<\/h1>\nThe first video in this chapter walks you through the basics of objects, vectors, and functions.\n\nObjects are the basic building blocks of the R language. They are what we create, manipulate, model, visualize in order to extract information from them. Vectors are a type of object in R. They are one-dimensional series of numbers, or characters, or logical expressions. In the video below, we'll create our first objects and vectors and conduct some basic manipulation using functions.\n\nFunctions are another key building block of the R language. Think of functions as verbs that we apply to objects. Functions do something to objects. This first video also introduces you to some basic functions.\n\n[embed]https:\/\/vimeo.com\/713115389[\/embed]\n<h1>Part 2 - Using functions to automatically create objects<\/h1>\nIn this section, we will expand our understanding of objects, vectors, and functions by generating vectors using three functions that automate that process based on parameters we set. It's less complicated and abstract than it sounds.\n\n[embed]https:\/\/vimeo.com\/713751539[\/embed]\n<h1>Part 3 - Logical and character vectors<\/h1>\nSo far in this chapter, we have examined numeric vectors. In this last section, we will examine the other two types of vectors we will encounter: logical and character vectors.\n\nWe will also introduce the concepts of vector recycling and coercion.\n\n[embed]https:\/\/vimeo.com\/714143471[\/embed]\n\nThis concludes your first steps with the R language. Hopefully, you are starting to understand how it works: we create objects, such as vectors, and then, we manipulate or extract information from these objects, using the appropriate functions. This is the logic we will apply throughout the semester, albeit with more complex objects and functions, but the underlying reasoning is the same.\n<div class=\"textbox textbox--key-takeaways\"><header class=\"textbox__header\">\n<p class=\"textbox__title\"><strong>Key functions used in this chapter<\/strong><\/p>\n\n<\/header>\n<div class=\"textbox__content\">\n\nPart 1\n<ul>\n \t<li><strong>c()<\/strong>: the function that creates basic objects and vectors;<\/li>\n \t<li><strong>sum()<\/strong>: the function that calculates the sum of all the elements in a numeric object;<\/li>\n \t<li><strong>min()<\/strong>: the functions that identifies the smallest value in a numeric object;<\/li>\n \t<li><strong>max()<\/strong>: the function that identifies the largest value in a numeric object;<\/li>\n \t<li><strong>mean()<\/strong>: the function that calculates the mean of a numeric object;<\/li>\n \t<li><strong>median()<\/strong>: the function that calculates the median of a numeric object;<\/li>\n \t<li><strong>summary()<\/strong>: the function that provides summary statistics for a numeric object;<\/li>\n \t<li><strong>length()<\/strong>: the function that calculates the length (number of elements) of a numeric object;<\/li>\n \t<li><strong>help()<\/strong>: the function that opens the help documentation on any function.<\/li>\n<\/ul>\nPart 2\n<ul>\n \t<li><strong>seq()<\/strong>: the function that generates a sequence of numbers;<\/li>\n \t<li><strong>rep()<\/strong>: the function that generate a repeating series of numbers;<\/li>\n \t<li><strong>sample()<\/strong>: the function that randomly generates a series of numbers;<\/li>\n \t<li><strong>sort()<\/strong>: the function that sorts a series of number in increasing or decreasing order.<\/li>\n<\/ul>\nPart 3\n<ul>\n \t<li><strong>paste()<\/strong>: the function that joins character vectors.<\/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>Now that we are familiar with our interface, it is time to get started with the actual R language. As we know from the previous chapter, R is a sophisticated calculator, specifically appropriate for statistics and data science.<\/p>\n<p>I highly recommend following along with the videos below in your own R Studio Cloud Workspace.<\/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 cover the following topics:<\/p>\n<ul>\n<li>objects;<\/li>\n<li>vectors;<\/li>\n<li>functions.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<p>With objects, vectors and functions, we are really getting into the R language so this is where things get serious.<\/p>\n<p>For those of you taking a class, you will be provided an empty script with only the instructions. You should type the tutorial code as you follow along. Writing code yourself, as opposed to just watching the videos or just running code provided by someone else, is the best way to learn and get more comfortable.<\/p>\n<h1>Part 1 &#8211; Introducing objects, vectors, and functions<\/h1>\n<p>The first video in this chapter walks you through the basics of objects, vectors, and functions.<\/p>\n<p>Objects are the basic building blocks of the R language. They are what we create, manipulate, model, visualize in order to extract information from them. Vectors are a type of object in R. They are one-dimensional series of numbers, or characters, or logical expressions. In the video below, we&#8217;ll create our first objects and vectors and conduct some basic manipulation using functions.<\/p>\n<p>Functions are another key building block of the R language. Think of functions as verbs that we apply to objects. Functions do something to objects. This first video also introduces you to some basic functions.<\/p>\n<p><iframe loading=\"lazy\" id=\"oembed-1\" title=\"Chapter 3 - Part 1 - Objects, Vectors, and Functions\" src=\"https:\/\/player.vimeo.com\/video\/713115389?dnt=1&amp;app_id=122963\" width=\"500\" height=\"281\" frameborder=\"0\"><\/iframe><\/p>\n<h1>Part 2 &#8211; Using functions to automatically create objects<\/h1>\n<p>In this section, we will expand our understanding of objects, vectors, and functions by generating vectors using three functions that automate that process based on parameters we set. It&#8217;s less complicated and abstract than it sounds.<\/p>\n<p><iframe loading=\"lazy\" id=\"oembed-2\" title=\"Chapter 3 - Part 2 - Objects, Vectors, and Functions\" src=\"https:\/\/player.vimeo.com\/video\/713751539?dnt=1&amp;app_id=122963\" width=\"500\" height=\"281\" frameborder=\"0\"><\/iframe><\/p>\n<h1>Part 3 &#8211; Logical and character vectors<\/h1>\n<p>So far in this chapter, we have examined numeric vectors. In this last section, we will examine the other two types of vectors we will encounter: logical and character vectors.<\/p>\n<p>We will also introduce the concepts of vector recycling and coercion.<\/p>\n<p><iframe loading=\"lazy\" id=\"oembed-3\" title=\"Chapter 3 - Part 3 - Objects, Vectors, and Functions\" src=\"https:\/\/player.vimeo.com\/video\/714143471?dnt=1&amp;app_id=122963\" width=\"500\" height=\"281\" frameborder=\"0\"><\/iframe><\/p>\n<p>This concludes your first steps with the R language. Hopefully, you are starting to understand how it works: we create objects, such as vectors, and then, we manipulate or extract information from these objects, using the appropriate functions. This is the logic we will apply throughout the semester, albeit with more complex objects and functions, but the underlying reasoning is the same.<\/p>\n<div class=\"textbox textbox--key-takeaways\">\n<header class=\"textbox__header\">\n<p class=\"textbox__title\"><strong>Key functions used in this chapter<\/strong><\/p>\n<\/header>\n<div class=\"textbox__content\">\n<p>Part 1<\/p>\n<ul>\n<li><strong>c()<\/strong>: the function that creates basic objects and vectors;<\/li>\n<li><strong>sum()<\/strong>: the function that calculates the sum of all the elements in a numeric object;<\/li>\n<li><strong>min()<\/strong>: the functions that identifies the smallest value in a numeric object;<\/li>\n<li><strong>max()<\/strong>: the function that identifies the largest value in a numeric object;<\/li>\n<li><strong>mean()<\/strong>: the function that calculates the mean of a numeric object;<\/li>\n<li><strong>median()<\/strong>: the function that calculates the median of a numeric object;<\/li>\n<li><strong>summary()<\/strong>: the function that provides summary statistics for a numeric object;<\/li>\n<li><strong>length()<\/strong>: the function that calculates the length (number of elements) of a numeric object;<\/li>\n<li><strong>help()<\/strong>: the function that opens the help documentation on any function.<\/li>\n<\/ul>\n<p>Part 2<\/p>\n<ul>\n<li><strong>seq()<\/strong>: the function that generates a sequence of numbers;<\/li>\n<li><strong>rep()<\/strong>: the function that generate a repeating series of numbers;<\/li>\n<li><strong>sample()<\/strong>: the function that randomly generates a series of numbers;<\/li>\n<li><strong>sort()<\/strong>: the function that sorts a series of number in increasing or decreasing order.<\/li>\n<\/ul>\n<p>Part 3<\/p>\n<ul>\n<li><strong>paste()<\/strong>: the function that joins character vectors.<\/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":3,"template":"","meta":{"pb_show_title":"","pb_short_title":"","pb_subtitle":"","pb_authors":[],"pb_section_license":""},"chapter-type":[49],"contributor":[],"license":[],"class_list":["post-26","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\/26","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\/26\/revisions"}],"predecessor-version":[{"id":27,"href":"https:\/\/libraryresources.nse.org.ng\/introduction2r\/wp-json\/pressbooks\/v2\/chapters\/26\/revisions\/27"}],"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\/26\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/libraryresources.nse.org.ng\/introduction2r\/wp-json\/wp\/v2\/media?parent=26"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/libraryresources.nse.org.ng\/introduction2r\/wp-json\/pressbooks\/v2\/chapter-type?post=26"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/libraryresources.nse.org.ng\/introduction2r\/wp-json\/wp\/v2\/contributor?post=26"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/libraryresources.nse.org.ng\/introduction2r\/wp-json\/wp\/v2\/license?post=26"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}