Re: [R] function sum for array

2011-11-18 Thread William Dunlap
com] Sent: Thursday, November 17, 2011 11:20 PM To: William Dunlap Subject: Re: [R] function sum for array thank you very much, despite of the fact that I didn't understand how it really works. Why have you put 1:2? S On Thu, Nov 17, 2011 at 9:40 PM, William Dunlap wrote: The following gi

Re: [R] function sum for array

2011-11-17 Thread R. Michael Weylandt
It might not be as general as you have in mind, but this works: X = array(1:24, c(2,3,4)) rowSums(X, dims = 2) Combined with aperm() it's pretty powerful. Michael On Thu, Nov 17, 2011 at 11:24 AM, Simone Salvadei wrote: > I'm looking for a function that allows to sum the elements of an array

[R] function sum for array

2011-11-17 Thread Simone Salvadei
I'm looking for a function that allows to sum the elements of an array along a dimension that can be different from the classical ones (rows or columns). Let's suppose for example that: - A is an array with dimensions 2 x 3 x 4 - I want to compute B, a 2 x 3 matrix with elements equal to the sum