R Lesson 1 – Vectors and Matrices

Last time we got all set up in R and now we’re ready to start writing some scripts.

Firstly, we’re gonna look at vectors. These are sequences of data elements that consist of the same basic type.

We can declare them like so:

And then we can even append to them too:

These are then useful for if we want to combine several vectors into matrices like so:

Matrices in R is essentially a two dimensional array with atomic types in it.

There are several ways of creating matrices, shown below:

With these data types you can do many different functions relating to matrix mathematics, and even machine learning because of the nature of the data structure.

Some examples of what can be done with matrices and vectors are shown below:

Next time

Next time, we will be looking at looping in R, conditionals and other functions that we can use.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Design a site like this with WordPress.com
Get started