Question

I have a List, R=

[[1]]
     [,1] [,2]
[1,]  100    0
[2,]    0  100

[[2]]
             [,1]       [,2]
[1,] 0.0006364031  0.2521204
[2,] 0.2521204236 99.9993643`

I'm suppose to do F %*% R

         F
[1,] 1 -6.264917e-04
[2,] 1  1.575666e-04

As in F[1,] matrix multiplied with R[[1]], F[2,] matrix multiplied with R[[2]]

How should i go bout doing that?

Sorry. I think I was misunderstood. What I really want is F[1,]%*%R[[1]]%*%t(F[1,]) and F[2,]%*%R[[2]]%*%t(F[2,]) @Sven Hohenstein

Was it helpful?

Solution

mapply("%*%", as.data.frame(t(F)), R, SIMPLIFY = FALSE)

$V1
     [,1]        [,2]
[1,]  100 -0.06264917

$V2
             [,1]     [,2]
[1,] 0.0006761289 0.267877

Update

To answer your second question:

lapply(R, function(x) F %*% x %*% t(F))

[[1]]
          [,1]      [,2]
[1,] 100.00004  99.99999
[2,]  99.99999 100.00000

[[2]]
             [,1]         [,2]
[1,] 0.0003597493 0.0005083061
[2,] 0.0005083062 0.0007183373

Update

To answer your updated question:

mapply(function(x, y) y %*% x %*% as.matrix(y), R, as.data.frame(t(F)), 
       SIMPLIFY = FALSE)

[[1]]
     [,1]
[1,]  100

[[2]]
             [,1]
[1,] 0.0007183373

OTHER TIPS

R <- list(matrix(c(100,0,0,100), 2), matrix(c(0.0006364031,0.2521204236,0.2521204,99.9993643), 2))
F <- matrix(c(1, 1, -6.264917e-04,  1.575666e-04), 2)

lapply(1:2, function(x) F[x,] %*% R[[x]])
## [[1]]
##      [,1]        [,2]
## [1,]  100 -0.06264917
## 
## [[2]]
##              [,1]     [,2]
## [1,] 0.0006761289 0.267877

Just by doing it:

> F[1,]%*%R[[1]]
     [,1]        [,2]
[1,]  100 -0.06264917


> F[2,]%*%R[[2]]
             [,1]     [,2]
[1,] 0.0006761289 0.267877

Was there some particular way you wanted those stored?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top