How to create Vectors, Matrices, and more in R (R Tutorial 1.4)

Introduction to R Programming: Learn how to create vectors and matrices and perform simple operations on them using the R programming language. You will learn how to use the “seq”, “rep”, “matrix”, and [] (square brackets) commands. This video is a tutorial for programming in R Statistical Software for beginners.

Here is an overview of the topics discussed in this video. You can click on the time stamp to jump to the specific topic.

0:00:29 how to create vectors in R for both numbers or objects using the “c” or “concatenate” command

0:01:09 how to create a sequence of integer values in R using the colon (:)

0:01:20 how to use “seq” command in R to create sequences

0:01:55 how to use “rep” command in R to create a vector of repeated numbers or characters

0:03:34 how to perform basic arithmetic functions on the elements of one vector in R

0:04:02 how to preform arithmetic functions on the corresponding elements of two vectors in R

0:04:59 how to extract elements of a vector using square brackets[] in R

0:06:08 how to create a matrix using “matrix” command in R

0:06:21 how to set the number of rows and columns in a matrix using “nrow” and “byrow” commands in R

0:07:05 how to use the square brackets to extract certain elements from a matrix in R

0:08:06 how to perform element-wise arithmetic functions in a matrix in R


Michael Ng'ang'a says:

Very helpful. GOD bless

Prudencia Kigosi says:

thank you very much for your help mr Marin, your videos are very clear and helpful, am not desperate any more, it took me days and years to find someone that can remind me how to use R again, you are an angel from above

Antonio J says:

Hi again, and thank you for your really good neutral pronunciation and slow speaking, for the non english people is a plus. +10!!!

Paramvir Singh says:

Thanks Marin…this makes it easy to learn R

Soutrik Chowdhury says:

sir, i am really fortunate to get hold of this course.can u post more videos for logistic regression analysis , clustering and decision tree in r . please

Anjana Devi says:

very useful to us thank u so much

Parminder S Kainth says:

Hello Sir, Myself parminder. Im good in excel now i came to know about R importance future in companies. i want to know more about R. I saw your videos till 3rd . its very interesting and valueable. i want to know can u send us assignments for begginers so that i can do practice at home.


how can i download the excel data that is being used in this video ?

Mortal Frame says:

How to subset both the diagonals of a matrix?

Melvin Noche says:

#MindBlown! How are you so good at explaining! What’s more awesome is being able to select the essential things that need be learned by a novice. Thank you!

Zachary Kirby says:

Mr. Marin, wonderful videos! Quick question, why does a vector yield a ‘numeric’ type but a sequence yields an ‘integer’ type? What is the difference? Also what is the ‘short hand’ for selecting the last element in a vector? Thank you!

Swarnkar Rajesh says:

At 8.32 it says you can extract Column, but it prints in row fashion. I think this is incorrect representation in R language. Mathematically, the slicing should yeild column vector not its transpose.

Laurelei Eggel says:

I don’t know if it is already in a video or not, but I didn’t find it, so could you explain me how I could add a column in a matrix that was in a data that I already imported on R?
Sorry for my english.
And thanks a lot for your videos.

heba khateb says:

amazing, great explanations. Actually I had a course today and I was very confused , thanks for help.

W.J. Veen, van der says:

Thanks a lot !!

shailendra patil says:

While we save the file as .Rdata and next time when we load how do we check the comments which we added ,, when i load and open i can just see objects in my workspace

Mojo 1990 says:

Hi Martin I find your videos really helpful,  thank you. I wanted to ask you, how would do you select  individual numbers from separate rows and columns  in the matrix ? is this possible ?

Abdessalam ounounou says:

very clear and helpful tutorials , great progressive explanation, thank’s !

teja mareddy says:

iam beginner for R programming i need how to write code in R

Aniket Chowdhury says:

Hello sir, ur videos are really helpful to me as i’m in learning phase right away. but the thing is that, how i could able to apply these things to some sort of complex assignment??? could u pls help me out on this regard.

İlknur Aydar says:

very informative….

Ester Nicolini says:

hello I’m new to R.
can you explain why R is used, when Matlab exist? Is it only because it’s free, or has other potential? thanks 🙂

Ajoeanna Brown says:

so, one quick question if two commands are synonymous how do you represent it using the R program? I.e. c(3:9) is equivalent to (rep(3:9, times=1)), both yield the same answer for lets say a command y, can you type it in such a way the R program reads it and understand they are both the same answer just expressed differently.

Multistats says:

The choice of “c” is for concatenate? When I first saw this, I kept thinking it represented the word “column”, as in column vector.
Very nice job, Mike! I enjoy these tutorials.

Vipin Chand says:

interesting and really useful, thank you +Marin for posting, can you pls explain the concept in video 7.37 i.e extracting matrix in row and column i am not able to follow that.

Harsha Kamat says:

I love your videos. I am new to R programming and they are very helpful and much easier to understand . Great work.

teja mareddy says:

Hi sir will you please upload R programming videos not R studio videos

ketan rohilla says:

Hey sir,
Its my second tutorial..
Its really help a lot and very effective
Each and every step was clear..
Thanks and teach us more about R (if there is more things which we need,except uploaded videos)

Dee.R says:


 Write a comment


Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!