0

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

ShinjiOno
  • 47
  • 5
  • Hi Guys, Thanks for the answer. If I wanna do F %*% R %*% t(F) instead, is there a simple way of doing it? – ShinjiOno Mar 13 '13 at 14:24
  • I have upvoted your answer there. – Glen_b Mar 13 '13 at 14:06
  • 1
    Please don't kill kittens! http://stackoverflow.com/questions/15370947/store-or-print-results-for-t-test-in-for-loop-r#comment21720500_15370947 – GSee Mar 13 '13 at 14:45
  • 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,]) – ShinjiOno Mar 13 '13 at 15:47
  • @Sven Hohenstein 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,]) – ShinjiOno Mar 13 '13 at 16:00

3 Answers3

6
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
Sven Hohenstein
  • 80,497
  • 17
  • 145
  • 168
3
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
Matthew Lundberg
  • 42,009
  • 6
  • 90
  • 112
3

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?

Glen_b
  • 7,883
  • 2
  • 37
  • 48
  • What if the list is long eg. R[[1]] to R[[100]] and i wan to do it in one command? – ShinjiOno Mar 13 '13 at 14:06
  • and I wanna do F %*% R %*% t(F) instead – ShinjiOno Mar 13 '13 at 14:06
  • 2
    *What if the list is long eg. R[[1]] to R[[100]] and i wan to do it in one command?* –- this question is already answered in response to your SO post. – Glen_b Mar 13 '13 at 14:08
  • > *and I wanna do F %*% R %*% t(F) instead?* Then I suggest you edit your stackoverflow question to add that, or post a new question over there. Don't post the same question to both places. – Glen_b Mar 13 '13 at 14:10
  • Sorry. I'm new. Will not double post in the future. Thanks for the fast response – ShinjiOno Mar 13 '13 at 14:19