[R] rownames of single row matrices

Jason Turner jasont at indigoindustrial.co.nz
Fri Jun 11 10:18:14 CEST 2004


On Fri, 2004-06-11 at 20:09, Robin Hankin wrote:
> Hi
> 
> I want to extract rows of a matrix, and preserve rownames even if only
> one row is selected.  

The infamous drop=TRUE default.  help("[") goes into this.

Your toy example, two ways:

> a <- matrix(1:9,3,3)
> rownames(a) <- letters[1:3]
> colnames(a) <- letters[1:3]
> a[1,,drop=FALSE]
  a b c
a 1 4 7
> a[1,,drop=TRUE]
a b c 
1 4 7 

Does that help?

Cheers

Jason




More information about the R-help mailing list