Getting Element-Wise Average Matrices of all 1st, 2nd, 3rd, etc. Elements of a Nested List in R

26 Views Asked by At

I don't even know how to name this question well so I'm sorry for the odd title.

I have a list called dat that is of length 10 (each a specific subject), as follows. list named dat

As you can see, each list element is of length 3 (ignore the one with length 2, it's just weird) and these "sublist" have different names (each representing a specific session) as such.

enter image description here

And then again, you can see each of these sub-elements themselves is of length 3. Those 3 elements are as follows: end of list

The thing that's important to me is the variable zmat which is basically a 12x12 z-scored correlation matrix. What I would like is to get average z-matrices (i.e. the result is a 12x12 matrix of element-wise averages) of all of the zmat variables for each subject's 1st session, 2nd session, and 3rd session. So for example, for the first average zmat, I would like the average of dat[[1]][[1]]$zmat, dat[[2]][[1]]$zmat, ect. (or in other words, the avg. of sub-LS131/20230127T121643, sub-LS132/20230127T113358, etc.).

Most answers I have seen are for performing functions on either lists of matrices, or sublists of matrices, neither of which is exactly my issue.

thanks!

0

There are 0 best solutions below