using lapply

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

using lapply

kthakk4
I have a function with the follow signare:

apply.strategy(instr, strat)

where instr and strat are both objects of classes instrument and strategy
respectively.

I want to apply this function to a list that holds objects of the class
instrument.

Currently I am doing this by explicit looping:

for(i in length(instr.list) ) {
    apply.strategy(instr.list[[i]], my.strat)
}

Is it possible to achieve this task by using one of the built in functions
in R? I have looked at lapply but can't quite figure out how to pass the
arguments.

What would be the performance implications of one method vs. the other?

Thanks,
Kushan

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: using lapply

Uwe Ligges-3


On 10.03.2011 03:46, Kushan Thakkar wrote:

> I have a function with the follow signare:
>
> apply.strategy(instr, strat)
>
> where instr and strat are both objects of classes instrument and strategy
> respectively.
>
> I want to apply this function to a list that holds objects of the class
> instrument.
>
> Currently I am doing this by explicit looping:
>
> for(i in length(instr.list) ) {
>      apply.strategy(instr.list[[i]], my.strat)
> }


lapply(instr.list, apply.strategy, strat=mystrat)

Uwe Ligges



>
> Is it possible to achieve this task by using one of the built in functions
> in R? I have looked at lapply but can't quite figure out how to pass the
> arguments.
>
> What would be the performance implications of one method vs. the other?
>
> Thanks,
> Kushan
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.