Message-ID: <D77E0214-E630-47C8-A5EC-6BCD88F7EF41@comcast.net>
Date: 2009-01-31T14:16:57Z
From: David Winsemius
Subject: Creating Sub-Matrix
In-Reply-To: <f62827120901310525g14d5729dn9b965ad6445d2d03@mail.gmail.com>
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:
> Hello,
>
> How do I get sub-matrix? Example, I would like to get matrix of size
> 3x7
> from the matrix of size 4x7. Meaning that I try to exclude one row
> of the
> original matrix.
>
> Thanks
> -rofizah-
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.