[R] Mean of matrices entries in list of lists

Flummi Inka.Roesel at gmx.net
Fri Nov 9 14:56:44 CET 2012


Hey there,

I've got a list of lists with matrices:
A list with 13 entries (representing years), each of them another list with
12 matrices (representing one month). In each matrix there are as many rows
as there are hours in the different months and 2 columns, since two
meteorological parameters are measured.
What I want to do is to calculate the hourly mean values for each month over
the whole 13 year period

for (j in 1:12){
(list[[1]][[j]] [1,1] + list[[2]][[j]]  [1,1] + ...... list[[13]][[j]][1,1]
)/13 
}

How can I do that nicely? 


Original code looks like this (zeilen[j] is the number of hours for j=1 =
January, 2 = february and so on):


mean_list<-list()


for (j in 1:12){

mean_list[[j]]<-matrix(0,nrow=zeilen[j], ncol=2)

	for (k in 1:zeilen[j]){
	mean_list[[j]][k,1]<-
(biglist_new[[1]][[j]][k,1]+biglist_new[[2]][[j]][k,1]+biglist_new[[3]][[j]][k,1]+biglist_new[[4]][[j]][k,1]+biglist_new[[5]][[j]][k,1]+biglist_new[[6]][[j]][k,1]+biglist_new[[7]][[j]][k,1]+biglist_new[[8]][[j]][k,1]+biglist_new[[9]][[j]][k,1]+biglist_new[[10]][[j]][k,1]+biglist_new[[11]][[j]][k,1]+biglist_new[[12]][[j]][k,1]+biglist_new[[13]][[j]][k,1])/13
	mean_list[[j]][k,2]<-
(biglist_new[[1]][[j]][k,2]+biglist_new[[2]][[j]][k,2]+biglist_new[[3]][[j]][k,2]+biglist_new[[4]][[j]][k,2]+biglist_new[[5]][[j]][k,2]+biglist_new[[6]][[j]][k,2]+biglist_new[[7]][[j]][k,2]+biglist_new[[8]][[j]][k,2]+biglist_new[[9]][[j]][k,2]+biglist_new[[10]][[j]][k,2]+biglist_new[[11]][[j]][k,2]+biglist_new[[12]][[j]][k,2]+biglist_new[[13]][[j]][k,2])/13
			}
}




--
View this message in context: http://r.789695.n4.nabble.com/Mean-of-matrices-entries-in-list-of-lists-tp4649054.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list