[R] n-dimensional vector operations

Peter Alspach PAlspach at hortresearch.co.nz
Tue Apr 21 03:23:20 CEST 2009


Tena koe Ken

I may be misunderstanding you, but it seems to me you have a four
dimensional array.  If so:

ken <- array(rnorm(5*3*2*10), dim=c(5,3,2,10))
ken[,1,1,]
ken[1,,1,]

may be sufficient to get you going.

HTH ....

Peter Alspach 

> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of Ken-JP
> Sent: Tuesday, 21 April 2009 12:58 p.m.
> To: r-help at r-project.org
> Subject: [R] n-dimensional vector operations
> 
> 
> 
> 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-tp231476
> 07p23147607.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at 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.
> 

The contents of this e-mail are confidential and may be subject to legal privilege.
 If you are not the intended recipient you must not use, disseminate, distribute or
 reproduce all or any part of this e-mail or attachments.  If you have received this
 e-mail in error, please notify the sender and delete all material pertaining to this
 e-mail.  Any opinion or views expressed in this e-mail are those of the individual
 sender and may not represent those of The New Zealand Institute for Plant and
 Food Research Limited.




More information about the R-help mailing list