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
• 11,360 points
554 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,840 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,250 points
1,186 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
• 52,350 points
622 views
+1 vote
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
• 52,350 points
2,367 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,700 points
1,819 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,720 points
2,253 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,720 points
1,924 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,720 points

edited Jun 9, 2020 by Gitika 1,183 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,720 points
1,343 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,840 points
1,527 views
+1 vote
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,840 points
4,860 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP