Beginner Data Structures in R
Vectors in R

Course Description 

This module introduces you to the some of the basic data structures that can be used in R.   

Learning Objectives 

The objectives of this module are to provide you with an understanding of: 

  • What a vector is in R.
  • How to create a sequence.  
  • How to create a vector using a repetition.  
  • How to pull elements out of vectors.  
  • Vectorised operations. 
  • Logical comparisons.  
  • Strings in R.  
  • Undefined situations in mathematics.
  • 0, NA, NaN, and Null.

Intended Audience 

Aimed at all who wish to learn the R programming language. 


No prior knowledge of R is assumed. 

Delegates should already be familiar with basic programming concepts such as variables, scope, and functions. 

Experience of another scripting language such as Python or Perl would be an advantage. 

Having an understanding of mathematical concepts will be beneficial.


We welcome all feedback and suggestions - please contact us at to let us know what you think. 


We can create a vector in R by combining different values into a vector. By doing so, we have created a variable known as victor in the global environment pane. This can be called to the screen by typing in the name of the variable, victor, and we can see the vector on the screen. A vector is the simplest type of data structure in R. It is a sequence of data elements, all of the same basic type. These elements can be referred to as components. So each of my different one, two, three, four are components of my vector known as victor. These elements are ordered, and each has a unique index. 

In this case, the one here refers to the index of the first element. I can create vectors for different measurements, such as movie ratings. Maybe I went to see the same film three times, or I add three different people giving me three different ratings for the same film. I could also use a vector to measure different films for each of my three friends. And so I would maybe have my ratings stored in one vector, as such. Jane's ratings stored in a separate vector. Lenny's ratings stored in a separate vector. 

I can find out the number of individual values stored by using the length command. I can append and edit my ratings. If I ended up seeing another film that I wanted to attach to the original four films I've seen. I can combine various different people's ratings, many different vectors together. There are some basic types that we should have, which include the numerics, the logicals, characters, integers, and complex. These are known as the basic types. To repeat the statement at the beginning, a vector is sequence of data elements of the same basic type.

About the Author
Learning Paths

Kunal has worked with data for most of his career, ranging from diffusion markov chain processes to migrating reporting platforms.  

Kunal has helped clients with early stage engagement and formed multi week training programme curriculum. 

Kunal has a passion for statistics and data; he has delivered training relating to Hypothesis Testing, Exploring Data, Machine Learning Algorithms, and the Theory of Visualisation. 

Data Scientist at a credit management company; applied statistical analysis to distressed portfolios. 

Business Data Analyst at an investment bank; project to overhaul the legacy reporting and analytics platform. 

Statistician within the Government Statistical Service; quantitative analysis and publishing statistical findings of emerging levels of council tax data. 

Structured Credit Product Control at an investment bank; developing, maintaining, and deploying a PnL platform for the CVA Hedging trading desk.