|
```{r}
p=3
n=4
x=matrix(1:(n*p),ncol=p)
m_m <- function(x){
y <- as.data.frame(as.matrix(x)%*%as.matrix(t(x)))
}
(result_list <- apply(x,2,m_m))
(output <-as.matrix(Reduce(`+`, result_list)))
```
## [[1]]
## V1 V2 V3 V4
## 1 1 2 3 4
## 2 2 4 6 8
## 3 3 6 9 12
## 4 4 8 12 16
##
## [[2]]
## V1 V2 V3 V4
## 1 25 30 35 40
## 2 30 36 42 48
## 3 35 42 49 56
## 4 40 48 56 64
##
## [[3]]
## V1 V2 V3 V4
## 1 81 90 99 108
## 2 90 100 110 120
## 3 99 110 121 132
## 4 108 120 132 144
(output <-as.matrix(Reduce(`+`, result_list)))
## V1 V2 V3 V4
## [1,] 107 122 137 152
## [2,] 122 140 158 176
## [3,] 137 158 179 200
## [4,] 152 176 200 224
|