I have two large matrices P and Q around (10k x 50k dim in both, but to test this yourself a random 10x10 matrix for P and Q is sufficient). I have a list of indices, e.g.
i    j
1    4
1    625
1    9207
2    827
...  ...
etc. This means that I need to find the dot product of column 1 in P and column 4 in Q, then column 1 in P and column 625 in Q and so on. I could easily solve this with a for loop but I know they are not very efficient in R. Anyone got any ideas?
edit: asked for a reproducible example
P <- matrix(c(1,0,1,0,0,1,0,1,0), nrow = 3, ncol = 3) 
Q <- matrix(c(0,0,1,0,1,0,1,0,1), nrow = 3, ncol = 3) 
i <- c(1,1,2) 
j <- c(2,1,3)
gives output (if in dot product form)
1: 0
2: 1
3: 1
 
     
     
    