[R] n-dimensional vector operations

Ken-JP kfmfe04 at gmail.com
Tue Apr 21 02:57:31 CEST 2009



Let's start with a concrete case of n=3 dimensions.

Along dimension x, I have a matrix of 5 vectors (each with ten rows)
Along dimension y, I have a matrix of 3 vectors (each with ten rows)
Along dimension z, I have a matrix of 2 vectors (each with ten rows)

I am trying to write a:

function(..., funcp) { } 

where funcp(...) is an operator which works on n vectors and returns a
numeric.  For example, averages n=3 columns (one from each dimension) and
takes the standard-deviation of the resultant vector.

So answer should be a matrix of dimension( 5, 3, 2 ) of numeric, in this
case.  At position (4, 2, 1) we would find the numeric answer to funcp(
x[,4],y[,2],z[,1] ).

------------------------------------------------------------
set.seed( 1 );
x <- matrix( runif( 50 ), nrow=10);
y <- matrix( runif( 30 ), nrow=10);
z <- matrix( runif( 20 ), nrow=10);

foo <- function(...,funcp)
{
  matrices <- list(...);
  n.matrices <- length( matrices );
  # What should I put here?!?! -------------------------------------
}



-- 
View this message in context: http://www.nabble.com/n-dimensional-vector-operations-tp23147607p23147607.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list