Hi Lazarus, You should use apply, not sapply.
> a =matrix(1:12, nrow=2,ncol=6,byrow=TRUE) > b = array(a,c(2,2,3));b > colMeans(b) > > f1=function(x) sum(x)/length(row(a.df[,1:2])) > y3 <- apply(b, 1, f1) > > It only gives one matrix with only two values, I expected 3 values. To apply the function on each submatrix, you have to apply it over the third index: y3 <- apply(b, 3, f1) Cheers, Tsjerk -- Tsjerk A. Wassenaar, Ph.D. post-doctoral researcher Molecular Dynamics Group * Groningen Institute for Biomolecular Research and Biotechnology * Zernike Institute for Advanced Materials University of Groningen The Netherlands ______________________________________________ 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.