FAQ

On Tue, Apr 09, 2002 at 07:12:08PM +0200, Peter Dalgaard BSA wrote:
Laurent Gautier <laurent@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.

...right... it was 'y[j]' and not 'y[,j]' (blurry eyes... looking too long at the screen)

this is probably what everybody already gave:
(I receive r-help few hours before the first ones to receive it)

x * matrix(y, ncol=ncol(x), nrow=nrow(x), byrow=T)

(I hope it work for good now... :) )

L.

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

## Related Discussions

 view thread | post posts ‹ prev | 7 of 11 | next ›
Discussion Overview
 group r-help categories r posted Apr 9, '02 at 12:46p active Apr 10, '02 at 4:06p posts 11 users 7 website r-project.org irc #r

### 7 users in discussion

Content

People

Support

Translate

site design / logo © 2018 Grokbase