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
am
#columns b & c
am[,c("b","c")]
#rows 3 to 7
am[3:7,]
#columns b & c & #rows 3 to 7
am[3:7,c("b","c")]
1 Like
Thank you, now i got the first part! I thought it way too complicated
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,
to=nrow(am),
by=2))
am[even_numbers,]
I'm sorry i mean that i should get every other row from one -> 1,3,5,7....n
Yes of course, silly me (I'm so tired that i consired even numbers as 2,4,6...)
But now i can go to sleep. Thank you for that!
system
Closed
December 17, 2020, 6:10pm
8
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.