Re: [R] summing array elements

2011-05-30 Thread marco milella
Thanks a lot for your help marco 2011/5/27 Thomas Lumley > On Fri, May 27, 2011 at 10:06 AM, marco milella wrote: > > Hi to everybody > > I have an array with dimensions 2,4,3,3. > > Wanting to sum the matrices in the first two dimensions, I'm trying to > use > > the "apply" function, but with

Re: [R] summing array elements

2011-05-30 Thread marco milella
Thanks a lot for your hint marco 2011/5/27 Erich Neuwirth > > arr<-1:72 > > dim(arr)<-c(2,4,3,3) > > apply(arr,1:2,sum) > [,1] [,2] [,3] [,4] > [1,] 297 315 333 351 > [2,] 306 324 342 360 > > apply(arr,3:4,sum) > [,1] [,2] [,3] > [1,] 36 228 420 > [2,] 100 292 484 > [3,]

Re: [R] summing array elements

2011-05-26 Thread Erich Neuwirth
> arr<-1:72 > dim(arr)<-c(2,4,3,3) > apply(arr,1:2,sum) [,1] [,2] [,3] [,4] [1,] 297 315 333 351 [2,] 306 324 342 360 > apply(arr,3:4,sum) [,1] [,2] [,3] [1,] 36 228 420 [2,] 100 292 484 [3,] 164 356 548 > apply(arr,1:2,sum) will sum all elements arr(i1,i2,..) for each

Re: [R] summing array elements

2011-05-26 Thread Thomas Lumley
On Fri, May 27, 2011 at 10:06 AM, marco milella wrote: > Hi to everybody > I have an array with dimensions 2,4,3,3. > Wanting to sum the matrices in the first two dimensions, I'm trying to use > the "apply" function, but with no results. Have to say I'm quite new with R > syntax. Tell apply() whi