Re: [R] lapply() reccursively

2009-10-13 Thread Kaveh Vakili
Thanks, Chuck's answer is the closest to what i want (gives the same result as cumprod()) ...but using this function seems actually slower than the loop (is it normal ?): a1<-runif(10) cadd<-function(x) Reduce("*", x, accumulate = TRUE) looop<-function(a1){ j<-length(a1) for(i in 2:j){ a1[i

Re: [R] lapply() reccursively

2009-10-13 Thread Kaveh Vakili
Thanks,Chuck answer is the closest to what i want (gives the same result as cumprod()) ...but using this function seems actually slower than the loop (is it normal ?): a1<-runif(10) cadd<-function(x) Reduce("*", x, accumulate = TRUE) looop<-function(a1){ j<-length(a1) for(i in 2:j){ a1[i]<-

Re: [R] lapply() reccursively

2009-10-13 Thread Kaveh Vakili
Thanks, this is the closest to what i want (gives the same result as cumprod()) ...but using this function seems actually slower than the loop (is it normal ?): a1<-runif(10) cadd<-function(x) Reduce("*", x, accumulate = TRUE) looop<-function(a1){ j<-length(a1) for(i in 2:j){ a1[i]<-a1[i-1

Re: [R] lapply() reccursively

2009-10-13 Thread Kaveh Vakili
Thanks, Chuck's answer is the closest to what i want (gives the same result as cumprod()) ...but using this function seems actually slower than the loop (is it normal ?): a1<-runif(10) cadd<-function(x) Reduce("*", x, accumulate = TRUE) looop<-function(a1){ j<-length(a1) for(i in 2:j){ a1[i

Re: [R] lapply() reccursively

2009-10-13 Thread Charles C. Berry
On Tue, 13 Oct 2009, Kaveh Vakili 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,

Re: [R] lapply() reccursively

2009-10-13 Thread hadley wickham
> Neither a1 nor 2:100 are lists, so it would seem that sapply would be more > appropriate. The difference between lapply and sapply is the output, not the input. Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/m

Re: [R] lapply() reccursively

2009-10-13 Thread David Winsemius
On Oct 13, 2009, at 7:33 AM, Kaveh Vakili 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) Neither a1 nor 2:100