i

R Programming Complete Tutorial

R Matrix construction

Matrix Operations

Till now, we have only discussed the one-dimensional data structure. And now, in this section, we will continue with Matrix. Matrices are the R objects, in which the elements are arranged in a two dimensional rectangular layout. So, we have to define row and column for Matrix.

Matrix construction

A matrix is constructed using the Matrix () function. The basic syntax contains data, nrows, ncol, byrow, and dimnames. 

Matrix Construction:

In this example, we are going to construct a matrix with a vector of 6 elements, nrow = 2 and nclo=3. It will construct a matrix of 2 rows and 3 columns.