- Home
- Training Library
- 3. Beginner Data Structures in R

# Vector Recycling in R

## Contents

###### Fundamentals of R

## The course is part of this learning path

**Difficulty**Beginner

**Duration**38m

**Students**16

**Ratings**

### 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

- [Instructor] When multiplying one vector by another, we see a vectorized operation occurring. But what happens when, we've run out of elements to consider. For example, if I was to use a flip flop vector of two, of length two. This doesn't really make sense mathematically. Whereas, where if I wrote this out by pen and paper, each vector would have to have the same length and here, we have a length of six and in the flip flip vector, we have a length of two. Yet in R, this does make sense. Why does the above multiplication make sense? The two elements of flip flop are reused or recycled when multiplying by prices. That is to say, we take the first pair, six and five and then we repeat with the second pair, three and four. And then we repeat again with the final pair, two and a one. The small vector is repeated to the needed length of the larger vector. To explain what's going on behind the scenes, let's consider the length of prices, let's consider the length of flip flip, let's consider the division of the larger one by the smaller one and what we needed to repeat, in order to ensure that flip flop became the same length as prices. Now behind the scenes of our initial multiplication of our two vectors, this is what's going on behind the scenes. Where does vector recycling fail? If, for example, the longer object was not a multiple of the shorter object length. For example, if I was to try prices multiplied by this vector of four, we'd return a warning on the screen.

# About the Author

**Students**122

**Labs**1

**Courses**11

**Learning paths**1

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.