1. Home
  2. Training Library
  3. 3. Beginner Data Structures in R

Generating Vectors in R

Developed with
QA

Contents

keyboard_tab

The course is part of this learning path

Fundamentals of R
course-steps 11 lab-steps 1 description 1
play-arrow
Generating Vectors in R
Overview
DifficultyBeginner
Duration38m
Students17
Ratings
5/5
star star star star star

Description

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, & Null  

Intended Audience 

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

Pre-requisites 

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 

Feedback 

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

Transcript

- A vector is a sequence. For example, you might have axis on a graph, you have sequentary units, you might have time measurements, you might have various different runs of a scientific experiment. In order to create or generate a regular sequence, we could use the colon operator. This would construct a vector from n through til m. The length of this can be found using the length function, and returns the number nine because we take our starting point as two and we raise until 10. We could have done this another way. Instead of using the colon operator, we could have used the sequence command or function. It would have returned exactly the same vector. However, we have more flexibility, or more optionality we could have had... Using the by argument of this function we can create a sequence that increases in increments of five from 10 until 50. If we wanted to better understand what the sequence function does, we can call for help on the screen by typing in question mark, and then follow it by sequence, seq by pressing enter at this point here. In the help tab of the bottom right pane of your RStudio session you can see the description of this function and the usage. I could have also done this using the help function. It does the same thing. I can create complicated sequences using very specific step sizes. Here I'm creating a sequence from four until 36, but I'm taking steps of eight where I input in a function or an equation. Let's say I wanted to create a sequence from zero to nine but selecting only the first three elements. I could do this by utilizing the parameter, length out equals three. So I'm having to specify the length of the output. We can also construct a vector out of repetitions. So I could repeat a single value, for example, four... For example, two four times utilizing the rep function, rep. And if I wanted to know more about that, I could use the question mark followed by rep, and that would tell me the description of this function, and the usage of this function, and the arguments in the help tab of the bottom right pane. I can repeat pairs of values, or I could repeat three lots of that value, but now with two of each element in the sequence.

About the Author

Students127
Labs1
Courses11
Learning paths1

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.