Skip to content
Prev 168761 / 398502 Next

Creating Sub-Matrix

Several ways, two are shown:
 > matrix(1:(4*7), 4,7)
      [,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,]    1    5    9   13   17   21   25
[2,]    2    6   10   14   18   22   26
[3,]    3    7   11   15   19   23   27
[4,]    4    8   12   16   20   24   28
 > mtx <- matrix(1:(4*7), 4,7)

 > mtx[-1,]
      [,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,]    2    6   10   14   18   22   26
[2,]    3    7   11   15   19   23   27
[3,]    4    8   12   16   20   24   28
 > mtx[2:4, ]
      [,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,]    2    6   10   14   18   22   26
[2,]    3    7   11   15   19   23   27
[3,]    4    8   12   16   20   24   28

Search terms:
--- at the R prompt
?Extract
?"["      #gets to the same page

--- in other sites:
indexing

--  
David Winsemius
On Jan 31, 2009, at 8:25 AM, Rofizah Mohammad wrote: