[R] Use apply on a function with multiple argument including a matrix ?

From: sunelav <julien.lavenus_at_hotmail.fr>
Date: Fri, 27 May 2011 12:34:04 -0700 (PDT)


Hello,

I wrote a function that takes a matrix M and several numeric parameters as arguments. It returns a square matrix (same number of rows than M). I need to use this function n times (n>1000) with random parameters.

I would like to increase the speed of this computation in order to increase the size of M I can use as an input. To do so, I would like to use a function of the apply family but I am not sure whether it is possible in my case. Have you got any idea ?

I initially thought I could create a list containing the vectors of the 3 random parameters and run lapply. However, in this case I don't know how to put M as another argument for the function.

Thank you very much for your help,
Cheers,

Sunelav.

To make things clearer; this is the loop I would like to eliminate

# the function

f=function(M,p1,p2,p3) # A matrix and 3 numeric parameters {....
return(SM) } # a square matrix

# the Loop

SM=f(M,p1,p2,p3)

for (i in 1:10000)
{ p1=runif(..); p2=runif(..); p3=runif(..)

   SM=SM+f(M,p1,p2,p3) }

--
View this message in context: http://r.789695.n4.nabble.com/Use-apply-on-a-function-with-multiple-argument-including-a-matrix-tp3556193p3556193.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
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.
Received on Fri 27 May 2011 - 20:44:49 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 27 May 2011 - 21:00:10 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive