[R] matrix with ncol=1

Christian Hennig hennig at stat.math.ethz.ch
Fri Feb 1 19:08:36 CET 2002


Hello list,

I try to optimize some R code and it turns out that the function as.matrix
takes a lot of time in my code. There is only one reason why I need
as.matrix: My code should work for matrices with ncol=p and p should be
allowed to be 1 or larger.

Now I have a matrix x with dim(x)=(n,p), and
I need to work with the submatrix y <-x[gv,], (gv a vector of
n logicals) and to calculate cov(y) and other functions for matrices. 
Unfortunately, if p=1, y is no longer a matrix, cov(y) gives an error,
and therefore I use y <- as.matrix(x[gv,]) which makes my program 
surprisingly slower (this is because lots of gv-vectors are needed).

Is there any way to handle submatrices of matrices with p=1 in the same
manner than with p>1 without using as.matrix?

Best,
Christian



-- 
***********************************************************************
Christian Hennig
Seminar fuer Statistik, ETH-Zentrum (LEO), CH-8092 Zuerich (current)
and Fachbereich Mathematik-SPST/ZMS, Universitaet Hamburg
hennig at stat.math.ethz.ch, http://stat.ethz.ch/~hennig/
hennig at math.uni-hamburg.de, http://www.math.uni-hamburg.de/home/hennig/
#######################################################################
ich empfehle www.boag.de


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list