Re: [R] Has For bucle be impooved in R

2017-08-07 Thread jim holtman
If you run it under the profiler in RStudio, you will see that the 'lm' call is taking about 2 seconds longer in the function which might have to do with resolving the reference. So it is probably the function call in 'lapply' vs. the in-line statement in the 'for' loop that account for the

Re: [R] Has For bucle be impooved in R

2017-08-07 Thread Thierry Onkelinx
Dear Jesus, The difference is marginal when each code chunk does the same things. Your for loop does not yields the same output as the lapply. Here is the cleaned version of your code. n<-1 set.seed(123) x<-rnorm(n) y<-x+rnorm(n) rand.data<-data.frame(x,y) k<-100 samples <- split(sample(n),

Re: [R] Has For bucle be impooved in R

2017-08-07 Thread David L Carlson
oun...@r-project.org] On Behalf Of Jesús Para Fernández Sent: Monday, August 7, 2017 9:30 AM To: r-help@r-project.org Subject: [R] Has For bucle be impooved in R Hi! I am doing a lapply and for comparaison and I get that for is faster than lapply. What I have done: n<-10 set.se

Re: [R] Has For bucle be impooved in R

2017-08-07 Thread Jeff Newmiller
The lapply loop and the for loop have very similar speed characteristics. Differences seen are almost always due to how you use memory in the body of the loop. This fact is not new. You may be under the incorrect assumption that using lapply is somehow equivalent to "vectorization", which it is

[R] Has For bucle be impooved in R

2017-08-07 Thread Jesús Para Fernández
Hi! I am doing a lapply and for comparaison and I get that for is faster than lapply. What I have done: n<-10 set.seed(123) x<-rnorm(n) y<-x+rnorm(n) rand.data<-data.frame(x,y) k<-100 samples<-split(sample(1:n),rep(1:k,length=n)) res<-list() t<-Sys.time() for(i in 1:100){