R Matrix – Usage, Operations & Applications of Matrix in R

1. R Matrix – Objective

In our previous blog, we have studied R Introduction and R Data Types in detail. Hope you are familiar with R now. So, in this blog on R Matrix, we will discuss the R Matrices in detail. Moreover, we will see what is Matrices in R, and history of Matrices. Also, we will discuss how to use Matrices. At last, we will cover various operations that we can perform on R matrices with examples, Applications of Matrices in detail.

So, let’s start the R Matrix Tutorial.

R Matrix - Usage, Operations & Applications of Matrix in R

R Matrix – Usage, Operations & Applications of Matrix in R

2. What is R Matrix?

First of all, we will discuss what exactly R matrix is. A matrix is a two-dimensional rectangular data set and thus it can be created using vector input to the matrix function. In addition, a matrix is a collection of numbers arranged into a fixed number of rows and columns. Usually, the numbers are the real numbers. By using a matrix function we can reproduce a memory representation of the matrix in R.

Hence, the data elements must be of the same basic type.

A = matrix (
c(2 , 4, 3, 1, 5, 7)       # the data elements
nrow =2,                   # no. of rows
ncol =3,                   # no. of columns
byrow = TRUE)             # fill matrix by rows
A                          # print the matrix
[,1]    [,2]    [,3]
[1,]     2       4       3
[2,]     1       5       7

An element at the mth row, the nth column of A can be accessed by using this expression A[m, n]

A[2, 3]      # element at 2nd row, 3rd column
[1] 7

The entire mth row A can extract as A[m, ].

A[2,]        # the 2nd row
[1] 1 5 7

The entire nth column A can extracted as A[ ,n].

A[ ,3]       # the 3rd column
[1] 3

3. History of Matrix

The history of matrices goes back to the ancient times! But the matrix was not applied to the concept till 1850.

“Matrix” is the Latin word for womb. It can also mean more generally any place in which something formed or produced. The word has used in unusual ways by at least two authors of historical importance. They proposed this axiom as a means to reduce any function to one of the lower types so that at the “bottom” (0order) the function is identical to its extension.

By using the process of Generalization any possible function other than a matrix derived from a matrix that is, by considering the proposition which asserts that the function in question is true with all possible values or with some value of one of the arguments, the other argument or arguments remaining undetermined”.

4. Uses of Matrix in R

Here we will explain the uses of R Matric. Various method to solve the matrices are discussed below with the examples-

i. Matrix Sum in R

To sum up two R Matrix, add the no. in matching positions:

For Example:

[1]  [2]              [1]  [2]       [1]  [2]
[1]   2    4    +    [1]    1    3    =    [1]   3    7
[2]   3    6         [2]    8    5         [2]   11  11

These are the calculations

2+1=3       4+3=7
3+8=11      6+5=11

ii. Negative

The negative of the R Matrix is also simple:

For Example:

[1]  [2]             [1]   [2]
[1]    2   -4    =   [1]   -2     4
[2]   -3    6        [2]    3    -6

iii. Subtracting

To subtract two R Matrix, subtract the no. in matching positions:

For Example:

[1]  [2]            [1]  [2]         [1]  [2]
[1]   3    8    -   [1]   4    0    =    [1]   -1    8
[2]   4    6        [2]   1   -9         [2]    3    15

These are the calculations

3-4=-1    8-0=8
4-1=3     6-(-9) =15

iv. Multiply by a constant

We can multiply an R matrix by some value:

For Example:

[1]   [2]             [1]  [2]
2   *  [1]    4     0    =    [1]   8    0
[2]    1    -9         [2]   2   -18

v. Matrix Multiplication in R

Let us take this matrix multiplication in r example

[1]   [2]  [3]           [1]  [2]             [1]   [2]
[1]   1     2    3   *   [1]   7    8    =   [1]    58    64
[2]   4     5    6       [2]   9   10       [2]   139   154
[3]  11   12

The “dot product” is where you multiply matching members, sum up:

These are the calculations:

(1*7+2*9+3*7)  +   (1*8+2*10+3*12)   =   58    64
(4*7+5*9+6*11) +   (4*8+5*10+6*12)      139   154

vi. Dividing

A/B = A * (1/B) = A * inverse (B)summmm

vii. Transposing

To “transpose” a matrix swaps rows and columns:

For Example:

[1]   [2]                [1]   [2]   [3]
[1]    6     4      =    [1]    6     1     2
[2]    1    -9           [2]    4    -9     4
[3]    2     4 

viii. Order of Multiplication

When you change the order of multiplication, the answer is different. It means AB is not equal to BA.

ix. Identity Matrix

The “identity matrix” is the equal of the number “1”

[1]   [2]   [3]
[1]    1     0     0
[2]    0     1     0
[3]    0     0     1

It is a special matrix because when you multiply by it, the original matrix remains unchanged:

I * A = A
A * I = A

R Quiz

5. Applications of Matrices

  • In geology, Matrices is been used for taking surveys and hence, used for plotting graphs, statistics, and studies in almost different fields.
  • To represent the real world data are like traits of people’s population. They are best representation method for plotting common survey things.
  • In robotics and automation, matrices are the best elements for the robot movements.
  • Matrices are used in calculating the gross domestic products in economics. Therefore, it helps in calculating the goods product Efficiency.
  • In computer-based application, matrices play a vital role in the projection of three-dimensional image into two-dimensional screen creating the realistic seeming motions.
  • In physical related applications, matrices can be applied in the study of an electrical circuit.

So, this was all on R Matrix and Matrices in general.

6. Conclusion – R Matrix

Hence, we have studied in detail about R matrices. Moreover, we learned about uses of matrices and we also called it operations which we perform on other matrices functions by using this. So, this above-mentioned information is sufficient enough to understand matrices and their uses.

Hope you find this blog on R Matrix.helpful. Still, you have any query related to R matrices so please leave a comment below.

See Also-

2 Responses

  1. Rachel says:

    I still don’t understand in what cases matrices might be more useful than vectors. It seems like you can multiply, divide, etc. vectors just as easily as matrices and matrices don’t necessarily put the values in any order that the vector doesn’t? So I don’t understand the purpose of making matrices out of vectors.

Leave a Reply

Your email address will not be published. Required fields are marked *