[R] using lapply

Uwe Ligges ligges at statistik.tu-dortmund.de
Thu Mar 10 10:32:30 CET 2011



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]]
>
> ______________________________________________
> 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.



More information about the R-help mailing list