If you are confused to use any Functions or operations in R , Just type question Mark and function name , You will get the documentation of the function in Help pane.
Creating First matrix :
Here we are creating our first Matrix : Variable my_data is created and iam trying to print 1 to 20 Numbers.
Variable matrix is created and pass the arguments my_data, number of rows = 4, Number of colums = 5
we can see in the console pane Matrix is built with 4 rows and 5 Colums.
From this below matrix from console pane , if i want to print Number 10 which is located in second row and third column
We can index this by writing the syntax : Matrix[2,3]
Now Let’s Create a Matrix by passing argument byrow = TRUE
Here in the Line 13, matrixb Variable is created, and iam passing matrix Variable data, the number of rows is 4 and Number of colums is 5, we passed it just like below we created, here in addition we are passing another argument byrow = TRUE/T.
Now Let’s see rbind ()& cbind() Functions in R:
rbind()
function is used to combine specified Vector, Matrix or Data Frame by rows.
Syntax: rbind(x1, x2, …, deparse.level = 1)
Parameters:
x1, x2: vector, matrix, data frames
deparse.level: This value determines how the column names generated. The default value of deparse.level is 1.
Let’s do a quick example to understand how rbind() works:
we can see the Output displayed in Console Pane, It is Binding all the three vectors by rows.
cbind()
function is used to combine specified Vector, Matrix or Data Frame by Colums
Syntax: cbind(x1, x2, …, deparse.level = 1)
Parameters:
x1, x2: vector, matrix, data frames
deparse.level: This value determines how the column names generated. The default value of deparse.level is 1.
Let’s do a quick example to understand how cbind() works:
we can see the Output displayed in Console Pane, It is Binding all the three vectors by columns.