[R] a question regarding apply

Rajarshi Guha rxg218 at psu.edu
Thu Jun 3 17:38:14 CEST 2004


Hi,
  I have a matrix, m, over whose rows I want to apply a function. I also
have a vector, r, whose length is equal to the rows of m.

The obvious way is:

result <- apply( m, c(1), fun )

However the function call requires the row from m and the corresponding
element of r.

So, I want to pass m[i,] and r[i] to the function.

Currently I use a loop. But can this be modified to use apply (or
related functions)?

Thanks,

-------------------------------------------------------------------
Rajarshi Guha <rxg218 at psu.edu> <http://jijo.cjb.net>
GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE
-------------------------------------------------------------------
Q: What do you get when you cross a Post Modernist with a Mafioso?
A: An offer you can't understand.




More information about the R-help mailing list