Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Semrush - keyword research tool

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Teach Your Child To Read

Disclosure: My content contains affiliate links.

31,615 questions

41,668 answers

573 users

How to subtract two matrices in R

1 Answer

0 votes
vec <- c(1, 2, 3, 1, 0, 2, 3, 1, 1)
m1 <- matrix(vec, nrow = 3, ncol = 3)
  
vec <- c(2, 1, 3, 0, 0, 1, 2, 1, 0)
m2 <- matrix(vec, nrow = 3, ncol = 3)
 
subtract <- m1 - m2
   
print(m1)
print(m2)
print(subtract)
  
  
  
    
    
# run:
#
#      [,1] [,2] [,3]
# [1,]    1    1    3
# [2,]    2    0    1
# [3,]    3    2    1
#      [,1] [,2] [,3]
# [1,]    2    0    2
# [2,]    1    0    1
# [3,]    3    1    0
#      [,1] [,2] [,3]
# [1,]   -1    1    1
# [2,]    1    0    0
# [3,]    0    1    1
#

 



Learn & Practice Python
with the most comprehensive set of 13 hands-on online Python courses
Start now


answered Jul 7, 2021 by avibootz

Related questions

1 answer 85 views
1 answer 99 views
1 answer 76 views
76 views asked Jul 7, 2021 by avibootz
1 answer 89 views
1 answer 79 views
...