[R] Multiply each column of array by vector component
Henrique Dallazuanna
wwwhsd at gmail.com
Thu Nov 15 19:01:45 CET 2007
If i understand your question, you can do:
x <- matrix(1:10, 2)
y <- sample(10,5)
apply(x, 1, function(.x)mapply(y, .x, FUN="*"))
On 15/11/2007, M.T.Charemza at warwick.ac.uk <M.T.Charemza at warwick.ac.uk> wrote:
> Hi,
>
> I've got an array, say with i,jth entry = A_ij, and a vector, say with jth
> entry= v_j. I would like to multiply each column of the array by the
> corresponding vector component, i,e. find the array with i,jth entry
>
> A_ij * v_j
>
> This seems so basic but I can't figure out how to do it without a loop.
> Any suggestions?
>
> Michal.
>
> ______________________________________________
> R-help at r-project.org 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.
>
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O
More information about the R-help
mailing list