Re: [R] How to apply vector value function to a multidimensional array indexed by the remaining dimensions?

2010-10-02 Thread Henrik Bengtsson
apply() is your friend. You can specify more than one dimension in argument 'MARGIN'. Example: > x <- array(1:100,c(3,4,5)) > y <- apply(x, MARGIN=c(2,3), FUN=sum) > y [,1] [,2] [,3] [,4] [,5] [1,]6 42 78 114 150 [2,] 15 51 87 123 159 [3,] 24 60 96 132 168 [4,] 3

Re: [R] How to apply vector value function to a multidimensional array indexed by the remaining dimensions?

2010-10-01 Thread Charles C. Berry
On Fri, 1 Oct 2010, yunjiangster wrote: Hi, I am looking for some generalization of colSums and rowSums for general vector valued functions, and for arrays of more than 2 dimensions. So as a concrete example, suppose I have a 3 dimensional array, given by x = array(1:100,c(3,4,5)). and I want

[R] How to apply vector value function to a multidimensional array indexed by the remaining dimensions?

2010-10-01 Thread yunjiangster
Hi, I am looking for some generalization of colSums and rowSums for general vector valued functions, and for arrays of more than 2 dimensions. So as a concrete example, suppose I have a 3 dimensional array, given by x = array(1:100,c(3,4,5)). and I want to sum the 3rd index of x to obain a 3