-3

I have 3 matrix merged (second column are ID) as below:

NA        s_var1  s_var2 s_var3 s_var4
s_var1 1  1.0000  0.7665 0.2913 0.2681
s_var2 1 -0.0301  1.0000 0.9630 0.8734
s_var3 1  0.1066 -0.0047 1.0000 0.6261
s_var4 1  0.1118 -0.0161 0.0493 1.0000 
s_var1 2  1.0000  0.7665 0.2913 0.2681
s_var2 2 -0.0301  1.0000 0.9630 0.8734
s_var3 2  0.1066 -0.0047 1.0000 0.6261
s_var4 2  0.1118 -0.0161 0.0493 1.0000 
s_var1 3  1.0000  0.7665 0.2913 0.2681
s_var2 3 -0.0301  1.0000 0.9630 0.8734
s_var3 3  0.1066 -0.0047 1.0000 0.6261
s_var4 3  0.1118 -0.0161 0.0493 1.0000 

How can I can obtain a mean matrix of the 1, 2 and 3 matrix?

Thanks,

Leprechault
  • 1,531
  • 12
  • 28
  • I don't undetstand what you are asking. It would be better if you could provide you data in a more [reproducible format](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) (such as a `dput()`) to make the structure of your object more clear. Also, what exactly is the desired result here for this input data. What is the exact calculation you are trying to carry out? – MrFlick Mar 17 '16 at 21:38

1 Answers1

2

Let's assume that your matrix is named "M". Then this would give what I understand to be the "mean matrix" (for columns 3:5):

(M[ M[,2]==1, 3:5 ] +M[ M[,2]==2, 3:5 ]+M[ M[,2]==3, 3:5 ])/3

If that "first column" is actually a set of rownames then you would need to shift all the column indices down one unit. Better answers could be offered if you instead posted the output of dput(.) on your object.

IRTFM
  • 258,963
  • 21
  • 364
  • 487