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

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,961 questions

51,903 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 199 views
199 views asked Jul 7, 2021 by avibootz
1 answer 204 views
1 answer 198 views
198 views asked Jul 7, 2021 by avibootz
1 answer 193 views
1 answer 166 views
1 answer 185 views
185 views asked Jul 3, 2021 by avibootz
1 answer 205 views
...