Loading, please wait...

A to Z Full Forms and Acronyms

Explain Vectors in R programming Language | R Tutorial

Jun 24, 2021 #RLangauge #Programming, 458 Views
In this article, we will learn about the vectors in R programming language along with:What is a vector?Types of indexingTypes of vector

Explain Vectors in R programming Language | R Tutorial

In this article, we will learn about the vectors in R programming language along with:

  • What is a vector?
  • Types of indexing
  • Types of vector

Vector is the standard data structure. It is used to store and retrieve data of similar data types. It is one-dimensional variable storage. R extends its support to multiple built-in syntaxes to create the vector variable and assign it to the other variable. R language holds up all the primitive data types such as integer, character, double, and complex data types. The vector is accessed through indexing. It uses the c() functions to create the vector variable while writing the R language scripts. 

The index of a vector variable always starts from 1 and it uses square brackets([]) for indexing. Only with the help of indexing, we can access the components of the vector. 

The types of indexing are:

  • Indexing Using Position: Vector Indexing starts from 1, we can access the elements of the vector through it and also use the same to print the vector elements. 
  • Logical Indexing: It assigns the value true/false to the elements. If the value comes out to false then it drops the element from the result. 
  • Negative value indexing: The value starts from -1 in the negative value index. It is used to drop the element from the result. 
  • 0/1 indexing: It is so similar to logical indexing where 0 corresponds to FALSE and 1 corresponds to TRUE.

The vectors are broadly classified into two categories:

Atomic vectors

It is homogeneous in nature. There are 4 types of atomic vectors that exist: 

  • Logical: It is one of the simplest forms. It takes only 3 values such as TRUE, FALSE, and NA. These vectors are created using the combined function or through the comparison operator. 
  • Numeric: All numeric elements are integer and double. Everything numeric in the R language falls in the category of a double by default. To declare it as integer we have to add the L keyword after the number
  • Character: It is the complex data type of atomic vector. Character is just a string, nothing else. It can absorb any amount of data. The unique string will be stored only once as it uses a global string pool. It reduces the possibility of having duplicate strings in the global string pool. 

Recursive Vectors (Lists)

It is heterogeneous in nature. It can store another list as an element. The list can be created using the list() function in the R language. It can contain different types of objects. 

R language provides the function typeof() to check the type of vector. 

R language provides the function to find out the length of the vector element i.e length(). 

 

A to Z Full Forms and Acronyms