[R-sig-hpc] lapply() reccursively

Saptarshi Guha saptarshi.guha at gmail.com
Tue Oct 13 16:35:33 CEST 2009


Never used rapply but with lapply the <<- operator might help
Saptarshi

On Oct 13, 2009, at 7:24 AM, Kaveh Vakili <kaveh.vakili at ulb.ac.be>  
wrote:

> Hi all,
>
> I was wondering whether it is possible to use the lapply() function
> to alter the value of the input, something in the spirit of :
>
> a1<-runif(100)
> a2<-function(i){
>  a1[i]<-a1[i-1]*a1[i];a1[i]
> }
> a3<-lapply(2:100,a2)
>
> Something akin to a for() loop, but using the lapply() infrastructure.
> I  haven't been able to get rapply() to do this.
>
> The reason is that the "real" a2 function is a difficult function  
> that only needs to be evaluated if the value of a1[i-1] meets some  
> criteria.
>
> Thanks in advance,
>
> _______________________________________________
> R-sig-hpc mailing list
> R-sig-hpc at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-hpc



More information about the R-sig-hpc mailing list