我想为每四个矩阵应用一个函数,例如从1:4然后5:8然后9:12; 13:16,17:20,21:24开始,依此类推我的实际数据
k = 24; n=3; m = 4
ary=array(1:24, c(n,m,k))
str(ary)
int [1:3, 1:4, 1:24] 1 2 3 4 5 6 7 8 9 10 ...
for each four matrices in ary fun {.........}
答案 0 :(得分:1)
如果您想使用问题中建议的for
- 循环,请执行以下操作:
Seq <- seq(1, 24, 4)
for (i in Seq){
## i is 1, 5, 9, 13, 17, 21
ary[ , , i:(i+3)] #get's you the array with just four matrices
# do something ...
}