problem makin sub-materia from matrix

I have problem makin sub-materia (S) from matrix M.

To sub-materia i need to choose colums a,b &c and rows 20-120.

I tried like this, but it didn't work out:

S <- M [M $a & M $ b & M $ c &  20:120,,drop=FALSE $ M]

After that i should do a new sub-materia M1 from recently creates submateria M choosing sekond row.

This should go somelike:

M1 <- M [c(1, 3),]
but i dont know how to make it loop over and over again.

Here is a quick reminder about how to process select parts of matrices...

(am <- matrix(1:30,nrow=10,ncol=3))

colnames(am) <- letters[1:3]

#starting from this example matrix

#columns b & c 

#rows 3 to 7

#columns b & c & #rows 3 to 7
1 Like

Thank you, now i got the first part! I thought it way too complicated :smiley:

Still haven't figure out how to choose evere second row.

every second row ? There are actually many ways to do this.. here is an explicit way

(even_numbers <-seq(from=2,

I'm sorry i mean that i should get every other row from one -> 1,3,5,7....n

So change 'from' to 1 :slight_smile:

1 Like

Yes of course, silly me (I'm so tired that i consired even numbers as 2,4,6...) :joy:
But now i can go to sleep. Thank you for that!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.