[R] Simply matrix slice question

Jim Nemesh nemesh at broadinstitute.org
Fri Jul 24 04:44:18 CEST 2009


Is there any way to force a slice of a matrix to stay a matrix? R  
tends to convert a single row of a matrix into a vector.

Example:

z<-matrix (rnorm(20), ncol=5)
zz<-z[1,]
is.matrix(zz) #FALSE

I usually resort to:

zz<-matrix(z[1,], ncol=dim(z)[2], dimnames=list(rownames(z)[1],  
colnames(z)))

But that seems horribly kludgy.

Thanks!

-Jim




More information about the R-help mailing list