A matrix is a two-dimensional array in R. It contains the collection of elements of the same data type (numeric, character, or logical) arranged into a fixed number of rows and columns.
Problem:
Create a Matrix object in R
Solution:
A Matrix is created using the matrix() function.The syntax is as below:
matrix(data,nrow,ncol,byrow,dimnames)
Following is the description of each of the arguments used :
-
data: It is the collections of elements that will be arranged as rows and columns of the matrix.
-
nrow: It is the number of rows to be created.
-
ncol: It is the number of columns to be created.
-
byrow: It is a logical value i.e. TRUE or FALSE. If TRUE then the input vector elements are arranged by row.If we want the matrix to be filled by columns, we need to pass Byron = FLASE.
So, now as the Matrix is created, let’s focus on below:
https://oindrilasen.com/2017/09/naming-a-matrix-in-r/
https://oindrilasen.com/2017/09/adding-a-row-or-a-column-to-an-existing-matrix-in-r/
Thank You for reading!
0