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
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]<-
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
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
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,
> 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
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
7 matches
Mail list logo