[R] subsetting a matrix

Thomas W Blackwell tblackw at umich.edu
Tue Sep 30 19:34:44 CEST 2003

Rajarshi  -

Why not simply subscript your matrix X to return the rows and
columns you want to keep ?  For example,

new <- X[16:176, c(3,5,7,9)]

assuming those are the rows and columns you want.
See  help("Extract").

-  tom blackwell  -  u michigan medical school  -  ann arbor  -

On Tue, 30 Sep 2003, Rajarshi Guha wrote:

>   I'm trying to take a set of rows and columns out of a matrix. I hve
> been using the index aray approach. My overll matrix is X and is 179 x
> 65. I want to take out 4 columns and 161 rows.
> Thus I made a 161 x 2 array I and filled it up with the row,col indices.
> However doing,
> X[ I ] gives me a vector of the extracted elements. Is there anyway I
> can coerce this into a 161 x 4 matrix?
> -------------------------------------------------------------------
> Rajarshi Guha <rxg218 at psu.edu> <http://jijo.cjb.net>
> GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE
> -------------------------------------------------------------------

More information about the R-help mailing list