R中3D阵列列表的均值 [英] Mean of a list of 3D arrays in R

查看:89
本文介绍了R中3D阵列列表的均值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何计算R中列表中存储的数组的均值?结果应该是包含均值的相同大小的数组.例如:

How can I calculate the means of arrays stored in a list in R? The result should be an array of the same size containing the means... For example:

a1 <- array(runif(100), dim=c(4, 5, 5))
a2 <- array(runif(100), dim=c(4, 5, 5))
a3 <- array(runif(100), dim=c(4, 5, 5))
a4 <- array(runif(100), dim=c(4, 5, 5))
a5 <- array(runif(100), dim=c(4, 5, 5))

l <- list(a1, a2, a3, a4, a5)

[...]

应导致包含均值的4、5、5维数组.

should result in an array of dimension 4, 5, 5 containing the means.

我可以使用以下方法来处理矩阵列表:

I can do it for a list of matrices with:

apply(simplify2array(myList), 1:2, mean)

但这对我而言不起作用...

but it doesn't work for my purpose...

感谢任何线索!

推荐答案

也许我们可以使用Reduce

Reduce(`+`, l)/length(l)

这篇关于R中3D阵列列表的均值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆