An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090131/affd1673/attachment-0001.pl>
Creating Sub-Matrix
4 messages · Philipp Pagel, David Winsemius, Rofizah Mohammad
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.
Just exclude the row by negative indexing - e.g. foo[-2,] You may want to consider reading the "Introduction to R" where all these concepts are explained to new users. cu Philipp
Dr. Philipp Pagel Lehrstuhl f?r Genomorientierte Bioinformatik Technische Universit?t M?nchen Wissenschaftszentrum Weihenstephan 85350 Freising, Germany http://mips.gsf.de/staff/pagel
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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090131/e3b27c8a/attachment-0001.pl>