Dear all,

I am facing a challenge when applying the outer product with a matrix by rows.

What I have is a rather big matrix, which I would like to convert into a 
different matrix by doing something like

outer(matrix_row, vector, function(x,y) x[1]+5*x[4]/y)

In order to get there, I tried to get the matrix into a list using the mefa 
package, as subsetting the original data appears too complicated. However, if I 
apply the following code I always get a dimensional error, as the unlist() 
function is applied to the whole list.

library(mefa)
a<-matrix(c(1:6),ncol=3)
b<-c(1,2,3,4)
a<-mat2list(a,MARGIN=1)

outer(a,b,function(x,y){unlist(a)[1]+unlist(a)[3]/b})


Any idea how to do this more elegantly than a nested for-loop?

Many thanks,

Ingo

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to