Simple matrix logic in R

0 votes

A program that asks the user for the 8 values of a 2, 2x2 mathematical matrix. Another words, there are 4 values in one 2x2 matrix and another 4 values for the second matrix. And It should prompt a message to the user asking what operation they want to do with it like addition, subtraction, division, multiplication etc.

Oct 30, 2018 in Data Analytics by Ali
• 10,430 points
22 views

1 answer to this question.

0 votes

In R, if you have a matrix:

m1 <- matrix(c(2,2,2,2), ncol = 2)
m2 <- matrix(c(4,4,4,4), ncol = 2)  

and you want to add/subtract/divide/multiple the two you simply:

m1 + m2 
     [,1] [,2]
[1,]    6    6
[2,]    6    6

If you store the inputted values in a list, you can refer to it inside the matrix function as above:

matrix(user_input, ncol = 2)
#or
matrix(c(ui1, ui2, ui3, ui4), ncol = 2)
answered Oct 30, 2018 by Maverick
• 10,040 points

Related Questions In Data Analytics

0 votes
1 answer

Confusion matrix in R

A confusion matrix can be used to ...READ MORE

answered Jul 5, 2018 in Data Analytics by DataKing99
• 8,130 points
167 views
0 votes
1 answer

"Error in if" while trying to execute simple code in R

This caused non-logical data or missing values passed ...READ MORE

answered Oct 31, 2018 in Data Analytics by Kalgi
• 40,460 points
36 views
0 votes
1 answer

"subscript out of bounds" error in while executing simple R program

This is caused by trying to access ...READ MORE

answered Oct 31, 2018 in Data Analytics by Kalgi
• 40,460 points
98 views
0 votes
1 answer

Check if a matrix is diagonalizable in R Programming Language

On a given matrix, a, the first way ...READ MORE

answered Dec 24, 2018 in Data Analytics by Tyrion anex
• 8,270 points
30 views
0 votes
1 answer

By using dpylr package sum of multiple columns

Basically here we are making an equation ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,700 points
96 views
0 votes
1 answer

How to convert a text mining termDocumentMatrix into excel or csv in R?

By assuming that all the values are ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,700 points
115 views
0 votes
1 answer

In a dpylr pipline how to use sample and seq?

For avoiding rowwise(), I prefer to use ...READ MORE

answered Apr 6, 2018 in Data Analytics by DeepCoder786
• 1,700 points
76 views
0 votes
1 answer

How to create a list of Data frames?

Basically all we have to do is ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,700 points
69 views
0 votes
1 answer

How is R applied in real world?

R Programming gives a broad variety of ...READ MORE

answered Oct 29, 2018 in Data Analytics by Maverick
• 10,040 points
94 views
0 votes
1 answer

Difference between factor and as.factor in R programming

Hey @Ali, as.factor is a wrapper for ...READ MORE

answered Oct 29, 2018 in Data Analytics by Maverick
• 10,040 points
67 views