[R] matrix dimension and for loop

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Tue Apr 9 19:12:08 CEST 2002


Laurent Gautier <laurent at genome.cbs.dtu.dk> writes:

> On Tue, Apr 09, 2002 at 05:46:40AM -0700, sonchawan tamkaew wrote:
> > Dear all,
> > 
> > My questions are that if I have
> > 
> > > x<-rnorm(50)
> > > dim(x)<-c(10,5)
> > > y=1:5
> > > Z<-matrix(0,NROW(x),NROW(y))
> > > for (j in 1:NROW(y)) Z[,j]<-x[,j]*y[j]
> > 
> > 1. Is there any other way to write this without 'for'
> > loop?
> 
> 
> Z <- x * y
> 
> seems to do the job....

Nope. Try it with x <- matrix(1,10,5) and see.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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