[R] matrix with ncol=1

Chong Gu chong at stat.purdue.edu
Fri Feb 1 19:49:54 CET 2002


   X-Authentication-Warning: florence.ethz.ch: hennig owned process doing -bs
   Date: Fri, 1 Feb 2002 19:08:36 +0100 (CET)
   From: Christian Hennig <hennig at stat.math.ethz.ch>
   X-X-Sender:  <hennig at florence>
   MIME-Version: 1.0
   Content-Type: TEXT/PLAIN; charset=US-ASCII
   Sender: owner-r-help at stat.math.ethz.ch
   Precedence: SfS-bulk

   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
   _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


Does y<-x[gv,,drop=FALSE] work?
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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