

{"id":4261,"date":"2017-09-20T11:17:54","date_gmt":"2017-09-20T05:47:54","guid":{"rendered":"http:\/\/data-flair.training\/blogs\/?p=4261"},"modified":"2024-05-08T21:23:14","modified_gmt":"2024-05-08T15:53:14","slug":"r-vector","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/r-vector\/","title":{"rendered":"8 R Vector Operations with Examples &#8211; A Complete Guide for R Programmers"},"content":{"rendered":"<p>If you are struggling with the R vector concept, then you have landed on the right page. This article is specially designed to help you to create and access R vectors. Here you will learn to perform many operations on them and will discover important applications of R vectors.<\/p>\n<p>R vector is the basic data structure, which plays an essential role in R programming. So, let&#8217;s start with our tutorial.<\/p>\n<h2>What is R Vector?<\/h2>\n<p><em>A vector is a sequence of elements that share the same data type.<\/em> These elements are known as components of a vector.<\/p>\n<p>R vector comes in two parts: <strong>Atomic vectors<\/strong> and <strong>Lists.<\/strong> They have three common properties:<\/p>\n<ul>\n<li><em>Type function<\/em> &#8211; What it is?<\/li>\n<li><em>Length function<\/em> &#8211; How many elements it contains.<\/li>\n<li><em>Attribute function<\/em> &#8211; Extra arbitrary metadata.<\/li>\n<\/ul>\n<p>These data structures share one difference, that is, they differ in the type of their elements:\u00a0 All elements of an atomic vector must be of the same type, whereas the elements of a list can have different types.<\/p>\n<p><em><strong>We have discussed <a href=\"https:\/\/data-flair.training\/blogs\/r-list-tutorial\/\">R Lists<\/a>\u00a0in detail in our previous tutorial, you must check it.<\/strong><\/em><\/p>\n<h3>Atomic Vectors in R<\/h3>\n<p>There are four common types of R atomic vectors:<\/p>\n<h4>1. Numeric Data Type<\/h4>\n<p>Decimal values are referred to as numeric data types in R. If we assign a decimal value for any variable <em>g,<\/em> as given below then, g will become a numeric type.<\/p>\n<p><strong>For example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; #Author DataFlair\r\n&gt; g &lt;- 53.5 #Assigning a decimal value to g\r\n&gt; g #Printing the value of g<\/pre>\n<p>Adding the class:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; class(g) #Printing the class name of g<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Numeric-Data-Type-in-R-programming.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-55694\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Numeric-Data-Type-in-R-programming.png\" alt=\"R numeric Data Types Example\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Numeric-Data-Type-in-R-programming.png 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Numeric-Data-Type-in-R-programming-150x86.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Numeric-Data-Type-in-R-programming-300x171.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Numeric-Data-Type-in-R-programming-768x438.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Numeric-Data-Type-in-R-programming-1024x584.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Numeric-Data-Type-in-R-programming-520x297.png 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<h4>2. Integer Data Type<\/h4>\n<p>A numeric value with no fraction called integer data is represented by \u201cInt\u201d.\u00a0-54 and 23 are two of the examples of an integer. Int size is 2 bytes while long Int size is 4 byte.<\/p>\n<p>In order to assign an integer to a variable, there are two ways:<\/p>\n<ul>\n<li><strong>The first way is to use the as.integer() function:<\/strong><\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; a &lt;- as.integer(4) #Using as.integer()\r\n&gt; a #printing a<\/pre>\n<p>For checking data type:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; typeof(a) #checking data-type of a<\/pre>\n<ul>\n<li><strong>The second way is the appending of L to the value:<\/strong><\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; b &lt;- 4L #Appending L to 4 \r\n&gt; b #printing b<\/pre>\n<p>For checking data type:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; typeof(b) #Checking data-type of b<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/integer_data_type_in_r.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-55696\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/integer_data_type_in_r.png\" alt=\"R integer Data Types Example\" width=\"1294\" height=\"748\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/integer_data_type_in_r.png 1294w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/integer_data_type_in_r-150x87.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/integer_data_type_in_r-300x173.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/integer_data_type_in_r-768x444.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/integer_data_type_in_r-1024x592.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/integer_data_type_in_r-520x301.png 520w\" sizes=\"auto, (max-width: 1294px) 100vw, 1294px\" \/><\/a><\/p>\n<h4>3. Character Data Type<\/h4>\n<p>The character is held as the one-byte integer in memory. There are two ways to create a character data type value in R:<\/p>\n<ul>\n<li><strong>The first method is by typing a string between &#8221; &#8220;<\/strong><\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; x = \"DataFlair\"\r\n&gt; x<\/pre>\n<p>For determining the type of x:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; typeof(x)<\/pre>\n<ul>\n<li><strong>In order to convert a number into character, make use of as.character() function as follows:<\/strong><\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; y = as.character(42) \r\n&gt; y<\/pre>\n<p>For determining the type of y:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; typeof(y)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Character-Data-Type-in-R.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-55717\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Character-Data-Type-in-R.png\" alt=\"R Character Data Type with Example\" width=\"1300\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Character-Data-Type-in-R.png 1300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Character-Data-Type-in-R-150x86.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Character-Data-Type-in-R-300x171.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Character-Data-Type-in-R-768x438.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Character-Data-Type-in-R-1024x584.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Character-Data-Type-in-R-520x296.png 520w\" sizes=\"auto, (max-width: 1300px) 100vw, 1300px\" \/><\/a><\/p>\n<h4>4. Logical Data Type<\/h4>\n<p>A logical data type returns either of the two values &#8211; TRUE or FALSE based on which condition is satisfied.<\/p>\n<p><strong>For example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">a =3; b =6       #sample values\r\ng = a&gt;b               # is a larger than b?\r\ng                     #print the logical value<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Logical-Data-Type-in-R.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-55699 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Logical-Data-Type-in-R.png\" alt=\"R Logical Data Type with Example\" width=\"1296\" height=\"743\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Logical-Data-Type-in-R.png 1296w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Logical-Data-Type-in-R-150x86.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Logical-Data-Type-in-R-300x172.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Logical-Data-Type-in-R-768x440.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Logical-Data-Type-in-R-1024x587.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Logical-Data-Type-in-R-520x298.png 520w\" sizes=\"auto, (max-width: 1296px) 100vw, 1296px\" \/><\/a><\/p>\n<p><em><strong>Learn about the <a href=\"https:\/\/data-flair.training\/blogs\/r-data-types\/\">R Data Types<\/a> in detail<\/strong><\/em><\/p>\n<h3>How to Create Vector in R?<\/h3>\n<p>The <em>c()<\/em> function is used for creating a vector in R. This function returns a one-dimensional array, also known as vector.<\/p>\n<p><strong>For example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; x &lt;- c(1,2,3,4)\r\n&gt; x<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Creating-R-vectors.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-55718\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Creating-R-vectors.png\" alt=\"How to create vector in R \" width=\"1299\" height=\"743\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Creating-R-vectors.png 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Creating-R-vectors-150x86.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Creating-R-vectors-300x172.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Creating-R-vectors-768x439.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Creating-R-vectors-1024x586.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Creating-R-vectors-520x297.png 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<h4>Ways to Create Vectors in R<\/h4>\n<p>There are several other ways of creating a vector:<\/p>\n<p><strong>1. Using the Operator<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; x &lt;- 1:5\r\n&gt; x<\/pre>\n<p>For y operator:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; y &lt;- 5:-5\r\n&gt; y<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Create-R-vector-using-the-operator-.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-55731\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Create-R-vector-using-the-operator-.png\" alt=\"Create R vector using the operator\u00a0\" width=\"1298\" height=\"743\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Create-R-vector-using-the-operator-.png 1298w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Create-R-vector-using-the-operator--150x86.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Create-R-vector-using-the-operator--300x172.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Create-R-vector-using-the-operator--768x440.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Create-R-vector-using-the-operator--1024x586.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Create-R-vector-using-the-operator--520x298.png 520w\" sizes=\"auto, (max-width: 1298px) 100vw, 1298px\" \/><\/a><\/p>\n<p><strong>2. Create R vector using\u00a0seq() function<\/strong><\/p>\n<p>There are also two ways in this. The first way is to set the step size and the second method is by setting the length of the vector.<\/p>\n<ul>\n<li><strong>Setting step size with \u2018by\u2019 parameter:<\/strong><\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; seq(2,4, by = 0.4)<\/pre>\n<ul>\n<li><strong>Specifying length of vector with the \u2018length.out\u2019 feature:<\/strong><\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; seq(1,4, length.out = 5)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<h4><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Create-R-vector-using-seq-function-.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-55722\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Create-R-vector-using-seq-function-.png\" alt=\"Create R vector using\u00a0seq() function\u00a0\" width=\"1298\" height=\"744\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Create-R-vector-using-seq-function-.png 1298w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Create-R-vector-using-seq-function--150x86.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Create-R-vector-using-seq-function--300x172.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Create-R-vector-using-seq-function--768x440.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Create-R-vector-using-seq-function--1024x587.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Create-R-vector-using-seq-function--520x298.png 520w\" sizes=\"auto, (max-width: 1298px) 100vw, 1298px\" \/><\/a><\/h4>\n<p><em><strong>Must Learn &#8211; <a href=\"https:\/\/data-flair.training\/blogs\/r-vector-functions\/\">How to apply Functions over R Vectors<\/a><\/strong><\/em><\/p>\n<h3>How to Access Elements of R Vectors?<\/h3>\n<p>With the help of vector indexing, we can access the elements of vectors. Indexing denotes the position where the values in a vector are stored. This indexing can be performed with the help of integer, character or logic.<\/p>\n<h4>1. Indexing with Integer Vector<\/h4>\n<p>Unlike many programming languages like Python, C++, Java etc. where the indexing starts from 0, the indexing of vectors in R starts with 1.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; x<\/pre>\n<p>We can perform indexing by specifying integer value in square braces [ ] next to our vector.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; x[2] #indexing with vector<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Indexing-with-Integer-Vector-in-R.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-55734\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Indexing-with-Integer-Vector-in-R.png\" alt=\" Indexing with Integer Vector\" width=\"1298\" height=\"740\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Indexing-with-Integer-Vector-in-R.png 1298w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Indexing-with-Integer-Vector-in-R-150x86.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Indexing-with-Integer-Vector-in-R-300x171.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Indexing-with-Integer-Vector-in-R-768x438.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Indexing-with-Integer-Vector-in-R-1024x584.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Indexing-with-Integer-Vector-in-R-520x296.png 520w\" sizes=\"auto, (max-width: 1298px) 100vw, 1298px\" \/><\/a><\/p>\n<h4>2. Indexing with Character Vector<\/h4>\n<p>Character vector indexing can be done as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; x &lt;- c(\"One\" = 1, \"Two\" = 2, \"Three\" = 3)\r\n&gt; x[\"Two\"]<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Indexing-with-Character-Vector-in-R.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-55735\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Indexing-with-Character-Vector-in-R.png\" alt=\" Indexing with Character Vector\" width=\"1298\" height=\"740\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Indexing-with-Character-Vector-in-R.png 1298w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Indexing-with-Character-Vector-in-R-150x86.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Indexing-with-Character-Vector-in-R-300x171.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Indexing-with-Character-Vector-in-R-768x438.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Indexing-with-Character-Vector-in-R-1024x584.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Indexing-with-Character-Vector-in-R-520x296.png 520w\" sizes=\"auto, (max-width: 1298px) 100vw, 1298px\" \/><\/a><\/p>\n<h4>3. Indexing with Logic Vector<\/h4>\n<p>In logical indexing, the positions whose corresponding position has logical vector TRUE are returned. For example, in the below code, R returns the positions of 1 and 3, where the corresponding logical vectors are TRUE.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; a &lt;- c(1,2,3,4)\r\n&gt; a[c(TRUE, FALSE, TRUE, FALSE)]<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Logic-indexing-in-R.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-55723\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Logic-indexing-in-R.png\" alt=\"R logic Index with Example\" width=\"1296\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Logic-indexing-in-R.png 1296w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Logic-indexing-in-R-150x86.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Logic-indexing-in-R-300x172.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Logic-indexing-in-R-768x439.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Logic-indexing-in-R-1024x585.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Logic-indexing-in-R-520x297.png 520w\" sizes=\"auto, (max-width: 1296px) 100vw, 1296px\" \/><\/a><\/p>\n<h2>Operations in R\u00a0Vector<\/h2>\n<h4>1. Combining Vector in R<\/h4>\n<p>Functions\u00a0are used\u00a0to combine vectors.\u00a0In order to combine the two vectors in R, we will create two new vectors \u2018n\u2019 and \u2018s\u2019. Then, we will create another vector that will combine these two using c(n,s) as follows:<\/p>\n<p><strong>For example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; #Author DataFlair\r\n&gt; n = c(1, 2, 3, 4) \r\n&gt; s = c(\"Hadoop\", \"Spark\", \"HIVE\", \"Flink\")\r\n&gt; c(n,s)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Combining-vector-in-R.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-55704\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Combining-vector-in-R.png\" alt=\"Combine vector in R with Example\" width=\"1298\" height=\"743\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Combining-vector-in-R.png 1298w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Combining-vector-in-R-150x86.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Combining-vector-in-R-300x172.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Combining-vector-in-R-768x440.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Combining-vector-in-R-1024x586.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Combining-vector-in-R-520x298.png 520w\" sizes=\"auto, (max-width: 1298px) 100vw, 1298px\" \/><\/a><\/p>\n<p><em><strong>Wait! Have you checked &#8211; <a href=\"https:\/\/data-flair.training\/blogs\/data-structures-in-r\/\">Data Structures in R<\/a><\/strong><\/em><\/p>\n<h4>2. Arithmetic Operations on Vectors in R<\/h4>\n<p>Arithmetic operations on vectors can\u00a0be performed\u00a0member-by-member.<\/p>\n<p><strong>For example:<\/strong><\/p>\n<p>Suppose we have two vectors a and b:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; #Author DataFlair\r\n&gt; a = c (1, 3)\r\n&gt; b = c (1, 3)\r\n&gt; a + b #Addition<\/pre>\n<p>For subtraction:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; a - b #Subtraction<\/pre>\n<p>For division:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; a \/ b #Division<\/pre>\n<p>For remainder operation:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; a %% b #Remainder Operation\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Arithmetic-Operations-on-Vectors-in-R.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-55706\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Arithmetic-Operations-on-Vectors-in-R.png\" alt=\"R Arithmetic operations with Example\" width=\"1297\" height=\"746\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Arithmetic-Operations-on-Vectors-in-R.png 1297w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Arithmetic-Operations-on-Vectors-in-R-150x86.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Arithmetic-Operations-on-Vectors-in-R-300x173.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Arithmetic-Operations-on-Vectors-in-R-768x442.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Arithmetic-Operations-on-Vectors-in-R-1024x589.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Arithmetic-Operations-on-Vectors-in-R-520x299.png 520w\" sizes=\"auto, (max-width: 1297px) 100vw, 1297px\" \/><\/a><\/p>\n<h4>3. Logical Index Vector in R<\/h4>\n<p>By using a logical index vector in R, we can form a new vector from a given vector, which has the same length as the original vector. If the corresponding members of the original vector are included in the slice, then vector members are TRUE and otherwise FALSE.<\/p>\n<p><strong>For example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; #Author DataFlair\r\n&gt; S = c(\"bb\", \"cc\")\r\n&gt; L = c(TRUE, TRUE)       #Defining our Logical Vector\r\n&gt; S[L]                    #This will return elements of vector S that corrospond to logic vector L<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Logical-Index-Vector-in-R.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-55708\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Logical-Index-Vector-in-R.png\" alt=\"R Logical Index Vector in R with Example\" width=\"1296\" height=\"743\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Logical-Index-Vector-in-R.png 1296w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Logical-Index-Vector-in-R-150x86.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Logical-Index-Vector-in-R-300x172.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Logical-Index-Vector-in-R-768x440.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Logical-Index-Vector-in-R-1024x587.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Logical-Index-Vector-in-R-520x298.png 520w\" sizes=\"auto, (max-width: 1296px) 100vw, 1296px\" \/><\/a><\/p>\n<h4>4. Numeric Index<\/h4>\n<p>For indexing a numerical value in <a href=\"https:\/\/www.r-project.org\/foundation\/\">R<\/a>, we specify the index between square braces [ ]. If our index is negative, then R will return us all the values except for the index that we have specified. For example, specifying [-2] will prompt R to convert -2 into its absolute value and then search for the value that occupies that index.<\/p>\n<p><strong>For example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; # Author DataFlair\r\n&gt; x &lt;- c(\"aa\", \"bb\", \"cc\", \"dd\", \"ee\") #Creating our vector\r\n&gt; x[3]<\/pre>\n<p>For negative index:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; x[-2] #Using Negative Index<\/pre>\n<p>For out of range index:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; x[15] #Using an out-of-range index<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Numeric-Index.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-61233\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Numeric-Index.jpg\" alt=\"Numeric Index\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Numeric-Index.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Numeric-Index-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Numeric-Index-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Numeric-Index-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Numeric-Index-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Numeric-Index-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><em><strong>You must definitely explore the <a href=\"https:\/\/data-flair.training\/blogs\/r-numeric-and-character-functions\/\">Numeric and Character Functions in R<\/a><\/strong><\/em><\/p>\n<h4>5. Duplicate Index<\/h4>\n<p>The index vector allows duplicate values. Hence, the following retrieves a member twice in one operation.<\/p>\n<p><strong>For example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; # Author DataFlair\r\n&gt; s = c(\"aa\", \"bb\", \"cc\", \"dd\", \"ee\")\r\n&gt; s[c(2,3,3)]<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Duplicate-Index-in-R.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-55709\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Duplicate-Index-in-R.png\" alt=\"R duplicate Index with Example\" width=\"1300\" height=\"743\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Duplicate-Index-in-R.png 1300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Duplicate-Index-in-R-150x86.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Duplicate-Index-in-R-300x171.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Duplicate-Index-in-R-768x439.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Duplicate-Index-in-R-1024x585.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Duplicate-Index-in-R-520x297.png 520w\" sizes=\"auto, (max-width: 1300px) 100vw, 1300px\" \/><\/a><\/p>\n<h4>6. Range Indexes<\/h4>\n<p>To produce a vector slice between two indexes, we can use the colon operator &#8220;<strong>:<\/strong>&#8220;. It is convenient for situations involving large vectors.<\/p>\n<p><strong>For example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; # Author DataFlair\r\n&gt; s = c(\"aa\", \"bb\", \"cc\", \"dd\", \"ee\")\r\n&gt; s[1:3]<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Range-Indexes-in-R.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-55710\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Range-Indexes-in-R.png\" alt=\"R Range Index with Example\" width=\"1298\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Range-Indexes-in-R.png 1298w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Range-Indexes-in-R-150x86.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Range-Indexes-in-R-300x171.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Range-Indexes-in-R-768x438.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Range-Indexes-in-R-1024x585.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Range-Indexes-in-R-520x297.png 520w\" sizes=\"auto, (max-width: 1298px) 100vw, 1298px\" \/><\/a><\/p>\n<h4>7. Out-of-order Indexes<\/h4>\n<p>The index vector can even be out-of-order. Here is a vector slice with the order of first and second members reversed.<\/p>\n<p><strong>For example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; s [ c (2, 1, 3) ]<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Out-of-order-Indexes-in-R.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-55711\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Out-of-order-Indexes-in-R.png\" alt=\"Out-of-order Indexes in R With Example\" width=\"1298\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Out-of-order-Indexes-in-R.png 1298w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Out-of-order-Indexes-in-R-150x86.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Out-of-order-Indexes-in-R-300x171.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Out-of-order-Indexes-in-R-768x438.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Out-of-order-Indexes-in-R-1024x585.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Out-of-order-Indexes-in-R-520x297.png 520w\" sizes=\"auto, (max-width: 1298px) 100vw, 1298px\" \/><\/a><\/p>\n<h4>8. Named Vectors Members<strong style=\"font-family: Verdana, Geneva, sans-serif\">\u00a0<\/strong><\/h4>\n<p>We first create our vector of characters:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; v = c(\"Hadoop\", \"Spark\")\r\n&gt; v<\/pre>\n<p>Then, we name the first vector member as \u201cFirst\u201d and the second member as \u201cSecond\u201d.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; names(v) = c(\"First\", \"Second\")\r\n&gt; v<\/pre>\n<p>We retrieve the first member by its name as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; v[\"First\"]<\/pre>\n<p>We can also reverse the order using the character string index vector:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; v[c(\"Second\", \"First\")]<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Named-Vectors-Members-in-r.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-55713\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Named-Vectors-Members-in-r.png\" alt=\"R Named Vectors Members\u00a0 with Example\" width=\"1300\" height=\"743\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Named-Vectors-Members-in-r.png 1300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Named-Vectors-Members-in-r-150x86.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Named-Vectors-Members-in-r-300x171.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Named-Vectors-Members-in-r-768x439.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Named-Vectors-Members-in-r-1024x585.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Named-Vectors-Members-in-r-520x297.png 520w\" sizes=\"auto, (max-width: 1300px) 100vw, 1300px\" \/><\/a><\/p>\n<h3>Advanced Vector Operations<\/h3>\n<p>Beyond the fundamental operations outlined earlier, R offers advanced functionalities for manipulating vectors. These include functions for sorting vectors, finding unique elements, and reshaping data structures.<\/p>\n<p>Sorting vectors can be achieved using functions like sort() and order(), allowing for ascending or descending arrangements based on elements&#8217; values. Moreover, finding unique elements within a vector can be done with unique(), which returns a vector with only the unique elements present in the original vector.<\/p>\n<p>Additionally, R provides functions like reshape() and rbind() for reshaping vectors into different dimensions or combining multiple vectors into matrices or data frames.<\/p>\n<h3>Advantages of Vectors<\/h3>\n<p>One of the key advantages of R vectors is their support for vectorized operations, which enable efficient computation on large datasets. Vectorization allows R to perform operations on entire vectors at once, rather than iterating through each element individually. This not only simplifies code but also significantly improves performance, especially when dealing with extensive datasets. By leveraging vectorized operations, R programmers can write concise and expressive code that executes efficiently, making it an ideal choice for data manipulation and analysis tasks.<\/p>\n<h3>Applications of R Vectors<\/h3>\n<p>1. Vectors are used in machine learning for principal component analysis. They are extended to eigenvalues and eigenvector which are then used for performing decomposition in vector spaces.<\/p>\n<p>2. The input that is provided to the deep learning model is in the form of vectors. This vector consists of standardized data that is supplied to the input layer of the neural network.<\/p>\n<p>3. Vectors are also highly useful in developing support vector machine algorithms.<\/p>\n<p>4. Furthermore, vector operations are utilized in neural networks in the hidden layer for various operations like image recognition and text processing.<\/p>\n<h2>Summary<\/h2>\n<p>We have studied the R vector in detail. Also, we have mentioned the different type of vectors and how to use it. So, this above information will surely help the person who is not so much aware of vectors and their uses. R is a beautiful language. The more you learn R, the more you start liking it.<\/p>\n<p><em><strong>Now that you are a master of R Vectors, get ready for <a href=\"https:\/\/data-flair.training\/blogs\/r-matrix-operations-applications\/\">R Matrix Operations and Applications<\/a><\/strong><\/em><\/p>\n<p>Still, you have any query in R vector, please comment in the section given below. We will be glad to solve your doubts.<span hidden class=\"__iawmlf-post-loop-links\" data-iawmlf-links=\"[{&quot;id&quot;:2169,&quot;href&quot;:&quot;https:\\\/\\\/www.r-project.org\\\/foundation&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20251001075238\\\/https:\\\/\\\/www.r-project.org\\\/foundation\\\/&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-11 00:43:43&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-20 06:25:53&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-26 01:06:34&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-30 10:24:25&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-05 06:41:24&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-08 22:31:25&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-12 05:46:06&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-15 15:20:57&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-18 17:45:43&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-24 04:19:47&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-27 04:57:30&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-30 14:28:40&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-03 04:38:57&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-07 08:31:20&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-12 15:37:29&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-16 04:55:12&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-20 17:45:28&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-24 00:55:52&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-27 06:56:52&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-02 20:59:31&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-07 00:48:27&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-10 09:01:28&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-14 17:05:36&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-21 15:22:34&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-26 16:29:05&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-30 17:07:00&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-05 10:49:45&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-11 00:45:07&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-14 06:25:35&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-20 11:43:48&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-23 15:54:13&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-28 17:33:58&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-04 00:56:21&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-09 06:45:26&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-12 14:29:59&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-15 16:58:23&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-19 12:18:22&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-23 07:04:09&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-29 08:36:27&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-02 15:52:06&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-06 05:56:58&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-09 12:41:18&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-12 20:58:12&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-18 04:08:14&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-22 10:36:36&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-27 08:08:22&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-07-01 01:53:17&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-07-04 14:35:44&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-07-08 09:19:12&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-07-12 10:53:02&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-07-15 23:41:16&quot;,&quot;http_code&quot;:503}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-07-15 23:41:16&quot;,&quot;http_code&quot;:503},&quot;process&quot;:&quot;done&quot;}]\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you are struggling with the R vector concept, then you have landed on the right page. This article is specially designed to help you to create and access R vectors. Here you will&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":55725,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51],"tags":[19664,20361,11275,11276],"class_list":["post-4261","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-r","tag-r-atomic-vectors","tag-r-vector","tag-r-vector-operations","tag-r-vector-types"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>8 R Vector Operations with Examples - A Complete Guide for R Programmers - DataFlair<\/title>\n<meta name=\"description\" content=\"With this R vector tutorial, learn about the types of atomic vectors, ways to create vectors, accessing elements of R vectors with its operations and applications.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/r-vector\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"8 R Vector Operations with Examples - A Complete Guide for R Programmers - DataFlair\" \/>\n<meta property=\"og:description\" content=\"With this R vector tutorial, learn about the types of atomic vectors, ways to create vectors, accessing elements of R vectors with its operations and applications.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/r-vector\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2017-09-20T05:47:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-08T15:53:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Vectors-in-R-01.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"8 R Vector Operations with Examples - A Complete Guide for R Programmers - DataFlair","description":"With this R vector tutorial, learn about the types of atomic vectors, ways to create vectors, accessing elements of R vectors with its operations and applications.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/r-vector\/","og_locale":"en_US","og_type":"article","og_title":"8 R Vector Operations with Examples - A Complete Guide for R Programmers - DataFlair","og_description":"With this R vector tutorial, learn about the types of atomic vectors, ways to create vectors, accessing elements of R vectors with its operations and applications.","og_url":"https:\/\/data-flair.training\/blogs\/r-vector\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2017-09-20T05:47:54+00:00","article_modified_time":"2024-05-08T15:53:14+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Vectors-in-R-01.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/r-vector\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/r-vector\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"8 R Vector Operations with Examples &#8211; A Complete Guide for R Programmers","datePublished":"2017-09-20T05:47:54+00:00","dateModified":"2024-05-08T15:53:14+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/r-vector\/"},"wordCount":1409,"commentCount":8,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/r-vector\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Vectors-in-R-01.jpg","keywords":["R atomic vectors","R Vector","R vector operations","R vector Types"],"articleSection":["R Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/r-vector\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/r-vector\/","url":"https:\/\/data-flair.training\/blogs\/r-vector\/","name":"8 R Vector Operations with Examples - A Complete Guide for R Programmers - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/r-vector\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/r-vector\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Vectors-in-R-01.jpg","datePublished":"2017-09-20T05:47:54+00:00","dateModified":"2024-05-08T15:53:14+00:00","description":"With this R vector tutorial, learn about the types of atomic vectors, ways to create vectors, accessing elements of R vectors with its operations and applications.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/r-vector\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/r-vector\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/r-vector\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Vectors-in-R-01.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Vectors-in-R-01.jpg","width":802,"height":420,"caption":"R vector Tutorial"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/r-vector\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"R Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/r\/"},{"@type":"ListItem","position":3,"name":"8 R Vector Operations with Examples &#8211; A Complete Guide for R Programmers"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team provides industry-driven content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our expert educators focus on delivering value-packed, easy-to-follow resources for tech enthusiasts and professionals.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam2\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/4261","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=4261"}],"version-history":[{"count":15,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/4261\/revisions"}],"predecessor-version":[{"id":136994,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/4261\/revisions\/136994"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/55725"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=4261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=4261"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=4261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}