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

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

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

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,038 questions

40,803 answers

573 users

How to add 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)
 
add <- m1 + m2
   
print(m1)
print(m2)
print(add)
  
  
  
    
    
# 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,]    3    1    5
# [2,]    3    0    2
# [3,]    6    3    1
#

 





answered Jul 7, 2021 by avibootz

Related questions

1 answer 76 views
1 answer 95 views
1 answer 80 views
80 views asked Jul 7, 2021 by avibootz
1 answer 85 views
1 answer 75 views
...