you are looking for the outer product

?outer


> a <- 1:6
> cc <- matrix(1:6, 3, 2)


> e <- matrix(0, 6,3)
> for (j in 1:3) e[,j] <- a*cc[j,2]
> e
     [,1] [,2] [,3]
[1,]    4    5    6
[2,]    8   10   12
[3,]   12   15   18
[4,]   16   20   24
[5,]   20   25   30
[6,]   24   30   36


> a %o% cc[,2]
     [,1] [,2] [,3]
[1,]    4    5    6
[2,]    8   10   12
[3,]   12   15   18
[4,]   16   20   24
[5,]   20   25   30
[6,]   24   30   36
> >

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to