避免R中的嵌套for循环
我有一个很大的数组要填充。蛮力方法是对以下循环使用嵌套:避免R中的嵌套for循环,r,for-loop,permutation,R,For Loop,Permutation,我有一个很大的数组要填充。蛮力方法是对以下循环使用嵌套: size_1 <- 26460; size_2 <- 1782; size_total <- size_1 * size_2; counter = 0 link <- array(0, dim = c(size_total, 2)) for (i in c(1:size_1)) { for (j in c(1:size_2)) { counter = counter + 1; link[counter,1] &
size_1 <- 26460; size_2 <- 1782; size_total <- size_1 * size_2; counter = 0
link <- array(0, dim = c(size_total, 2))
for (i in c(1:size_1)) { for (j in c(1:size_2)) { counter = counter + 1;
link[counter,1] <- i; link[counter,2] <- j }}
size\u 1非常感谢!
link <- rbind( sort( matrix( permn(1:size_1)[[1]], nrow = 1, ncol = size_total), decreasing = FALSE ),
array( permn(1:size_2)[[1]], dim = size_total) )
rev(expand.grid(list(seq(size_2), seq(size_1))))
Var2 Var1
1 1 1
2 1 2
3 2 1
4 2 2
5 3 1
6 3 2