按R中的列将数组拆分为子数组,每个列具有不同的列数

时间:2017-10-16 18:21:28

标签: r sub-array

我已经有一段时间了,但似乎有问题。

我希望调整我已经开发的以下小脚本,以便输出' pop'由较小的子阵列组成,每个子阵列具有不同数量的列(但行数相同)。当K = 1时,只有一个数组。如果K> 1,我希望在' pop'中有K个子阵列。变量。

K <- 1 # number of arrays
N <- 10 # number of columns
Hstar <- 5 # maximum label value in array
perms <- 10 # number of rows

probs <- rep(1/Hstar, Hstar)

specs <- 1:N

pop <- array(dim = c(c(perms, N), K))

haps <- as.character(1:Hstar)

for(j in 1:perms){
    for(i in 1:K){
        pop[j, specs, i] <- sample(haps, size = N, replace = TRUE, prob = probs)
    }
}

pop
, , 1

      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,] "4"  "5"  "4"  "2"  "3"  "4"  "2"  "3"  "2"  "1"  
 [2,] "5"  "5"  "4"  "4"  "2"  "2"  "1"  "3"  "5"  "4"  
 [3,] "1"  "3"  "4"  "5"  "4"  "4"  "5"  "4"  "2"  "2"  
 [4,] "5"  "4"  "4"  "3"  "3"  "1"  "4"  "3"  "3"  "5"  
 [5,] "3"  "1"  "5"  "2"  "5"  "1"  "3"  "1"  "2"  "2"  
 [6,] "1"  "2"  "5"  "3"  "2"  "4"  "1"  "5"  "5"  "4"  
 [7,] "5"  "5"  "2"  "3"  "3"  "3"  "1"  "1"  "2"  "3"  
 [8,] "4"  "2"  "4"  "3"  "1"  "1"  "2"  "3"  "2"  "1"  
 [9,] "5"  "5"  "5"  "5"  "3"  "1"  "4"  "4"  "3"  "5"  
[10,] "1"  "1"  "5"  "4"  "4"  "3"  "4"  "2"  "4"  "3"  

在上面的输出中,我想分开“流行音乐”。按列,以便每个新子数组包含相同数量的行,但列数不同。

感谢任何帮助。

0 个答案:

没有答案