HI, Try this: set.seed(15) lst<- list(matrix(sample(1:15,20,replace=TRUE),ncol=5),matrix(sample(4:20,20,replace=TRUE),ncol=5),matrix(sample(8:25,20,replace=TRUE),ncol=5)) library(abind) arr1<-abind(lst,along=3) apply(arr1,c(1,2),median) # [,1] [,2] [,3] [,4] [,5] #[1,] 17 13 19 12 7 #[2,] 16 15 12 11 15 #[3,] 15 13 12 12 9 #[4,] 10 6 10 15 12
#or library(plyr) aaply(laply(lst,as.matrix),c(2,3),median) # X2 #X1 1 2 3 4 5 # 1 17 13 19 12 7 # 2 16 15 12 11 15 # 3 15 13 12 12 9 # 4 10 6 10 15 12 A.K. ----- Original Message ----- From: Lucas Holland <hollandlu...@gmail.com> To: "r-help@R-project.org" <r-help@r-project.org> Cc: Sent: Friday, March 22, 2013 5:17 PM Subject: [R] Median across matrices Hey all, I have a list of matrices. I'd like to calculate the median across all those matrices for each element. What I'd like to end up with is a matrix containing the median of all [1,1] [1,2] etc. elements across all matrices. Is there a concise way of doing that? Thanks! ______________________________________________ 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. ______________________________________________ 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.