Hi,
I have a matrix A and a vector b, and would like to apply a function
f(a,b) to the rows of A and the elements of b. Eg
A - matrix(1:4,2,2)
b - c(5,7)
f - function(a,b) {sum(a)*b}
myapply(f,A=A,b=b)
would give
(1+3)*5 = 20
(2+4)*7 = 42
I found mapply, but it does not work for matrices.
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Tamas K Papp
Sent: Wednesday, October 05, 2005 2:37 PM
To: R-help mailing list
Subject: [R] mapply for matrices
Hi,
I have a matrix A and a vector b, and would like to apply a function
f(a,b
Try this:
mapply(f, split(A, 1:nrow(A)), b)
On 10/5/05, Tamas K Papp [EMAIL PROTECTED] wrote:
Hi,
I have a matrix A and a vector b, and would like to apply a function
f(a,b) to the rows of A and the elements of b. Eg
A - matrix(1:4,2,2)
b - c(5,7)
f - function(a,b) {sum(a)*b}