[R] product of multidimensional tables

From: Nachiketa Sahoo <nsahoo_at_gmail.com>
Date: Tue 10 Jan 2006 - 05:43:08 EST


Hi,

I am trying to carry out the product between two multi dimensional tables, e.g. A with dim = c(2,2,3,4) and B with dim = c(2,3,4). So, I want to outer multiply each 3x4 table in A[i,j,,] with B[k,,] to get a table C of dim = c(2,2,3,4,3,4).

This arises in scenario of conditional probability tables. A could be a table taking probability values for different values of variables s,t,u,v and B taking values for different values of variables t,p,q. I want to get a table of factor (different from the factor in R) got by multiplying these two CPTs. The new table C will have dimensions (variables) s,t,u,v,p,q as a result of product of these two.

I am looking at the apply() method as an aid to get this done. But, it seems that I can't get a multidimensional output by applying any FUN funtion in apply(X, MARGIN, FUN, ...). for instance a outer product of two vectors gives back another vector and not a 2 dimensional array.

So, any thoughts on this? Any other place I should be looking at?

Thanks,
Nachi

        [[alternative HTML version deleted]]



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Jan 10 07:25:08 2006

This archive was generated by hypermail 2.1.8 : Tue 10 Jan 2006 - 14:17:15 EST