Grokbase Groups R r-help April 2002
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 7 of 11 | next ›
Discussion Overview
groupr-help @
categoriesr
postedApr 9, '02 at 12:46p
activeApr 10, '02 at 4:06p
posts11
users7
websiter-project.org
irc#r

People

Translate

site design / logo © 2017 Grokbase