Dear list,
I'm stuck with looking for a function of the *apply family, which I suppose
exists already – just I can't find it:
What I'm looking for is somewhere between sweep and mapply that does a
calculation vectorized over a matrix and a vector:
It should work complementary to sweep: for
Hi:
This is kind of kludgy, but if the matrix and parallel vector are both
numeric, you could try something like
A - matrix(rnorm(12), nrow = 3)
v - 1:3
f - function(x) c(sum(x[-length(x)]^2), x[length(x)])
t(apply(cbind(A, v), 1, f))
v
[1,] 8.196513 1
[2,] 1.414914 2
[3,] 2.436660
2 matches
Mail list logo