Hi there,

I have two questions on matrix manipulation. For the first one, I want to calculate the product of each column of a matrix (say A) with another vector (say b). That is, if A has 5 columns (a1, a2, a3, a4, a5), I want to obtain a matrix with columns (a1*b, a2*b, aA3*b, a4*b, a5*b). Can I do it directly, without using "for" loop?

For the second one, I have a matrix A of dimension 2 by n (say columns of a1, a2, ..., an), another matrix B of dimension 2 by 2. I want to obtain the vector with elements (t(a1) %*% B %*% a1, t(a2) %*% B %*% a2, ..., t(an) %*% B %*% an). Can I do it without using "for" loop?

Thanks a lot!

Lei Liu
Associate Professor
Division of Biostatistics
Department of Public Health Sciences
University of Virginia School of Medicine

http://people.virginia.edu/~ll9f/

______________________________________________
R-help@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.

Reply via email to