[R] How to manipulate an abitrary dimensioned array.

From: Mike Meyer <mikem_at_salter-point.com>
Date: Fri 28 Oct 2005 - 07:49:31 EST


If I have an n1 x n1 x 2 array X I can calculate, say, X[,,1]/X[,,2].

If it is a 4 dimensional array then I want to be able to calculate X[,,,1]/X[,,,2], and similarly for higher dimensions.

How can I write a function to do this in a general way without having to do a switch for each possible length(dim(X)). So I want a function g that will take an arbitrary dimensioned array, X, and return X[,,,1]/X[,,,2], etc. I know how to do this by turning X into a vector, then doing the division, then re-shaping as an array, but that doesn't seem very elegant.

What I think I am missing is how to paste/substitute/eval a bunch of commas into an array selection.

Thanks, --Mike

--
Mike Meyer,  Seattle WA

______________________________________________
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 Fri Oct 28 08:05:47 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:40:51 EST