Creating matrix in loops

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Creating matrix in loops

aguswushu
Hi! everyone, im new in the forum, im Agus, nice to met you all.

Well, im new in R and im having problems with my code, and maybe you can help me!, lets see:

Im using a matrix that it has 2464rows x 2464cols, and i have to make a smaller matrix every 56 rows and 56 cols, so i have not idea how to make a loop for it, im trying to use the "for" command, but i dont know if there is another one that can may be easier or better.

I put here my code, if that can help you, thanks!

a = 0
b = 1
c = 2464

u = seq(b, c, by=56)
v = seq(a, c, by=56)

n = 56
i = 1:n
j = 1:n

DOM1 <- MatrizCI[u[ 1 ]:v[ 2 ],u[ 1 ]:v[ 2 ]]
DOM2 <- MatrizCI[u[ 2 ]:v[ 3 ],u[ 2 ]:v[ 3 ]]
DOM3 <- MatrizCI[u[ 3 ]:v[ 4 ],u[ 3 ]:v[ 4 ]]
DOM4 <- MatrizCI[u[ 4 ]:v[ 5 ],u[ 4 ]:v[ 5 ]]
DOM5 <- MatrizCI[u[ 5 ]:v[ 6 ],u[ 5 ]:v[ 6 ]]
DOM6 <- MatrizCI[u[ 6 ]:v[ 7 ],u[ 6 ]:v[ 7 ]]
DOM7 <- MatrizCI[u[ 7 ]:v[ 8 ],u[ 7 ]:v[ 8 ]]
DOM8 <- MatrizCI[u[ 8 ]:v[ 9 ],u[ 8 ]:v[ 9 ]]
DOM9 <- MatrizCI[u[ 9 ]:v[ 10 ],u[ 9 ]:v[ 10 ]]
DOM10 <- MatrizCI[u[ 10 ]:v[ 11 ],u[ 10 ]:v[ 11 ]]
DOM11 <- MatrizCI[u[ 11 ]:v[ 12 ],u[ 11 ]:v[ 12 ]]
DOM12 <- MatrizCI[u[ 12 ]:v[ 13 ],u[ 12 ]:v[ 13 ]]
DOM13 <- MatrizCI[u[ 13 ]:v[ 14 ],u[ 13 ]:v[ 14 ]]
DOM14 <- MatrizCI[u[ 14 ]:v[ 15 ],u[ 14 ]:v[ 15 ]]
DOM15 <- MatrizCI[u[ 15 ]:v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]
DOM36 <- MatrizCI[u[ 36 ]:v[ 37 ],u[ 36 ]:v[ 37 ]]
DOM37 <- MatrizCI[u[ 37 ]:v[ 38 ],u[ 37 ]:v[ 38 ]]
DOM38 <- MatrizCI[u[ 38 ]:v[ 39 ],u[ 38 ]:v[ 39 ]]
DOM39 <- MatrizCI[u[ 39 ]:v[ 40 ],u[ 39 ]:v[ 40 ]]
DOM40 <- MatrizCI[u[ 40 ]:v[ 41 ],u[ 40 ]:v[ 41 ]]
DOM41 <- MatrizCI[u[ 41 ]:v[ 42 ],u[ 41 ]:v[ 42 ]]
DOM42 <- MatrizCI[u[ 42 ]:v[ 43 ],u[ 42 ]:v[ 43 ]]
DOM43 <- MatrizCI[u[ 43 ]:v[ 44 ],u[ 43 ]:v[ 44 ]]
DOM44 <- MatrizCI[u[ 44 ]:v[ 45 ],u[ 44 ]:v[ 45 ]]

It works, but i have to create a loop for reduce the linecodes, and find the way to create all the DOM1, DOM2...

And here, its my try of making a loop, i think that the "i" and "j" has to be something like that, but for sure it will make you laugh:

for (i in 1:n) {
  for (j in 2:n) {
    DOM <- MatrizCI[u[i]:v[j],u[i]:v[j]]
  }
}

Thanks!