I am cracking my head trying to figure out how to run a for loop to subset a matrix.
Essentially, I have a matrix m, and would like to subset the data at regular interval, and finally rbind them together. The laborious manner goes like this:
m1 <- m[7:22,2:25]
m2 <- m[30:45,2:25]
m3 <- m[53:68,2:25]
...
m100 <- ....
m_all <- rbind(m1,m2,m3 .... m100)
As you can see, the intervals is 23....
I would like to have a for loop command but am failing to remember what I learnt during my R classes. This is what I have thought of so far....
for (i=2 ; i<=100; i++)
{
m[i] <- m[(7+{i}*23):(22+{i}*23),2:25]
}
But my efforts are failing....
Is someone able to teach me how to design a for loop command?
Thanks for your help.