[R-SIG-Finance] Use apply/lapply/tapply functions
Rob Steele
gmain.20.phftt at xoxy.net
Wed Sep 3 16:52:24 CEST 2008
The looping functions (apply/lapply/tapply) can make your code cleaner
and easier to read but they can't speed it up. For that you need to
make the stuff in the loop faster, perhaps by vectorizing parts you're
currently doing serially.
Jorge Nieves wrote:
> Hi,
>
> I have a function that takes in a dataset ( a matrix of m rows by n
> columns), and five additional "constant" parameters, p1,p2,y1,y2,y3. The
> function perform a series of operations and transformations on the
> dataset, and returns a table of results.
>
> I have tested the function repeatedly and it works fine.
>
> However, I would like to generate a grid of results from myfunction for
> different values of two of the input parameters: p1, and p2.
>
> I have tried using for loops, and they work, but the computation time is
> a too long. I would like to use the apply/lapply/tapply functions to
> avoid using for loops, what ever works !!!
>
> Can someone recommend how to use these function to parameterize only a
> subset of the inputs into the function, i.e p1, and p2?
>
> Any tips/recommendations will be appreciated.
>
>
>
> myfunction = function (dataset, p1,p2,y1,y2,y3)
> {
>
> Line1
> Line2
> Line3
> ::::::::
> :::::::
> :::::::
> Return(res.table)
> }
>
>
More information about the R-SIG-Finance
mailing list