On Fri, May 27, 2011 at 10:06 AM, marco milella <vru...@gmail.com> 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() which dimensions you want to keep, in this case 3 and 4

R> m<-array(1, dim=c(2,4,3,3))
R> apply(m,3:4,sum)
     [,1] [,2] [,3]
[1,]    8    8    8
[2,]    8    8    8
[3,]    8    8    8

    -thomas

-- 
Thomas Lumley
Professor of Biostatistics
University of Auckland

______________________________________________
R-help@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.

Reply via email to